/
test_keyword_arguments.py
executable file
·178 lines (173 loc) · 5.82 KB
/
test_keyword_arguments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""Simple Facade Tests"""
import pytest
from . import my_testfnkw, testresult
from hdx.api import __version__
from hdx.facades.keyword_arguments import facade
from hdx.utilities.useragent import UserAgent, UserAgentError
class TestKeywordArguments:
def test_facade(self, monkeypatch, hdx_config_yaml, project_config_yaml):
UserAgent.clear_global()
my_user_agent = "test"
testresult.actual_result = None
facade(
my_testfnkw,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="site",
)
assert testresult.actual_result == "https://data.humdata.org"
UserAgent.clear_global()
testresult.actual_result = None
facade(
my_testfnkw,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="agent",
)
assert (
testresult.actual_result
== f"HDXPythonLibrary/{__version__}-{my_user_agent}"
)
UserAgent.clear_global()
testresult.actual_result = None
my_user_agent = "lala"
monkeypatch.setenv("USER_AGENT", my_user_agent)
facade(
my_testfnkw,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="agent",
)
assert (
testresult.actual_result
== f"HDXPythonLibrary/{__version__}-{my_user_agent}"
)
UserAgent.clear_global()
testresult.actual_result = None
facade(
my_testfnkw,
user_agent="test",
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="agent",
)
assert (
testresult.actual_result
== f"HDXPythonLibrary/{__version__}-{my_user_agent}"
)
UserAgent.clear_global()
testresult.actual_result = None
my_preprefix = "haha"
monkeypatch.setenv("PREPREFIX", my_preprefix)
facade(
my_testfnkw,
user_agent="test",
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="agent",
)
assert (
testresult.actual_result
== f"{my_preprefix}:HDXPythonLibrary/{__version__}-{my_user_agent}"
)
UserAgent.clear_global()
testresult.actual_result = None
my_test_key = "1234"
facade(
my_testfnkw,
hdx_key=my_test_key,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="api",
)
assert testresult.actual_result == my_test_key
UserAgent.clear_global()
testresult.actual_result = None
monkeypatch.setenv("HDX_KEY", "aaaa")
facade(
my_testfnkw,
hdx_key=my_test_key,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="api",
)
assert testresult.actual_result == my_test_key
UserAgent.clear_global()
testresult.actual_result = None
my_test_hdxsite = "stage"
facade(
my_testfnkw,
hdx_site=my_test_hdxsite,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="site",
)
assert (
testresult.actual_result
== f"https://{my_test_hdxsite}.data-humdata-org.ahconu.org"
)
UserAgent.clear_global()
testresult.actual_result = None
monkeypatch.setenv("HDX_SITE", "feature")
facade(
my_testfnkw,
hdx_site=my_test_hdxsite,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="site",
)
assert (
testresult.actual_result
== f"https://{my_test_hdxsite}.data-humdata-org.ahconu.org"
)
UserAgent.clear_global()
my_test_hdxurl = "http://other-data.humdata.org"
monkeypatch.setenv("HDX_URL", my_test_hdxurl)
facade(
my_testfnkw,
hdx_site="feature",
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="site",
)
assert testresult.actual_result == my_test_hdxurl
UserAgent.clear_global()
my_test_hdxurl2 = "http://other2-data.humdata.org/"
monkeypatch.setenv("HDX_URL", my_test_hdxurl2)
facade(
my_testfnkw,
hdx_url=my_test_hdxurl,
user_agent=my_user_agent,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="site",
)
assert testresult.actual_result == my_test_hdxurl
UserAgent.clear_global()
def test_exception(self, hdx_config_yaml, project_config_yaml):
UserAgent.clear_global()
testresult.actual_result = None
with pytest.raises(ValueError):
facade(
my_testfnkw,
user_agent="test",
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="exc",
)
UserAgent.clear_global()
with pytest.raises(UserAgentError):
facade(
my_testfnkw,
hdx_config_yaml=hdx_config_yaml,
project_config_yaml=project_config_yaml,
fn="agent",
)
UserAgent.clear_global()