3 |
3 |
from wcs.qommon.misc import get_variadic_url
|
4 |
4 |
from wcs.qommon.ezt import EZTException
|
5 |
5 |
|
|
6 |
from utilities import create_temporary_pub, clean_temporary_pub
|
6 |
7 |
|
7 |
|
def test_url_unchanged():
|
|
8 |
@pytest.fixture
|
|
9 |
def pub(request):
|
|
10 |
return create_temporary_pub()
|
|
11 |
|
|
12 |
def teardown_module(module):
|
|
13 |
clean_temporary_pub()
|
|
14 |
|
|
15 |
|
|
16 |
def test_url_unchanged(pub):
|
8 |
17 |
assert get_variadic_url('http://www.example.net/foobar', {}) == 'http://www.example.net/foobar'
|
9 |
18 |
|
10 |
19 |
|
11 |
|
def test_url_scheme():
|
|
20 |
def test_url_scheme(pub):
|
12 |
21 |
assert get_variadic_url('http[https]://www.example.net/foobar',
|
13 |
22 |
{'https': 's'}) == 'https://www.example.net/foobar'
|
14 |
23 |
assert get_variadic_url('http[https]://www.example.net/foobar',
|
... | ... | |
32 |
41 |
{'https': ''}) == 'http://www.example.net/foo/bar'
|
33 |
42 |
|
34 |
43 |
|
35 |
|
def test_url_netloc():
|
|
44 |
def test_url_netloc(pub):
|
36 |
45 |
assert get_variadic_url('http://[hostname]/foobar',
|
37 |
46 |
{'hostname': 'www.example.net'}) == 'http://www.example.net/foobar'
|
38 |
47 |
assert get_variadic_url('http://[hostname]/foobar',
|
... | ... | |
44 |
53 |
{'hostname': 'www.example.com'}) == 'http://www.example.com/foobar'
|
45 |
54 |
|
46 |
55 |
|
47 |
|
def test_url_netloc_port():
|
|
56 |
def test_url_netloc_port(pub):
|
48 |
57 |
assert get_variadic_url('http://www.example.net:[port]/foobar',
|
49 |
58 |
{'port': '80'}) == 'http://www.example.net:80/foobar'
|
50 |
59 |
assert get_variadic_url('http://www.example.net:{{ port }}/foobar',
|
51 |
60 |
{'port': '80'}) == 'http://www.example.net:80/foobar'
|
52 |
61 |
|
53 |
62 |
|
54 |
|
def test_url_path():
|
|
63 |
def test_url_path(pub):
|
55 |
64 |
assert get_variadic_url('http://www.example.net/[path]',
|
56 |
65 |
{'path': 'foobar'}) == 'http://www.example.net/foobar'
|
57 |
66 |
assert get_variadic_url('http://www.example.net/[path]',
|
... | ... | |
65 |
74 |
{'path': 'foo bar'}) == 'http://www.example.net/foo%20bar'
|
66 |
75 |
|
67 |
76 |
|
68 |
|
def test_url_query_variable():
|
|
77 |
def test_url_query_variable(pub):
|
69 |
78 |
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
|
70 |
79 |
{'world': 'world'}) == 'http://www.example.net/foobar?hello=world'
|
71 |
80 |
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
|
... | ... | |
91 |
100 |
{'world': 'a=b'}) == 'http://www.example.net/foobar?hello=a%3Db'
|
92 |
101 |
|
93 |
102 |
|
94 |
|
def test_url_query_key():
|
|
103 |
def test_url_query_key(pub):
|
95 |
104 |
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
|
96 |
105 |
{'hello': 'hello'}) == 'http://www.example.net/foobar?hello=world'
|
97 |
106 |
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
|
... | ... | |
117 |
126 |
{'hello': 'a=b'}) == 'http://www.example.net/foobar?a%3Db=world'
|
118 |
127 |
|
119 |
128 |
|
120 |
|
def test_url_query_whole():
|
|
129 |
def test_url_query_whole(pub):
|
121 |
130 |
assert get_variadic_url('http://www.example.net/foobar?[hello]',
|
122 |
131 |
{'hello': 'hello=world'}) == 'http://www.example.net/foobar?hello=world'
|
123 |
132 |
|
... | ... | |
127 |
136 |
{'hello': 'hello=world'}) == 'http://www.example.net/foobar?hello%3Dworld'
|
128 |
137 |
|
129 |
138 |
|
130 |
|
def test_url_netloc_port_and_path():
|
|
139 |
def test_url_netloc_port_and_path(pub):
|
131 |
140 |
assert get_variadic_url('http://www.example.net:[port]/foobar/[path]',
|
132 |
141 |
{'port': '80', 'path': 'baz'}) == 'http://www.example.net:80/foobar/baz'
|
133 |
142 |
assert get_variadic_url('http://www.example.net:[port]/foobar/[path]',
|
... | ... | |
141 |
150 |
{'port': '80', 'path': 'b z'}) == 'http://www.example.net:80/foobar/b%20z'
|
142 |
151 |
|
143 |
152 |
|
144 |
|
def test_url_whole():
|
|
153 |
def test_url_whole(pub):
|
145 |
154 |
assert get_variadic_url('[url]',
|
146 |
155 |
{'url': 'http://www.example.net/foobar'}) == 'http://www.example.net/foobar'
|
147 |
156 |
|
... | ... | |
149 |
158 |
{'url': 'http://www.example.net/foobar'}) == 'http://www.example.net/foobar'
|
150 |
159 |
|
151 |
160 |
|
152 |
|
def test_url_server():
|
|
161 |
def test_url_server(pub):
|
153 |
162 |
for url in ('http://www.example.net', 'http://www.example.net/'):
|
154 |
163 |
assert get_variadic_url('[url]/foobar',
|
155 |
164 |
{'url': url}) == 'http://www.example.net/foobar'
|
... | ... | |
180 |
189 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/foo/bar'
|
181 |
190 |
|
182 |
191 |
|
183 |
|
def test_url_server_qs():
|
|
192 |
def test_url_server_qs(pub):
|
184 |
193 |
assert get_variadic_url('[url]?foo=bar',
|
185 |
194 |
{'url': 'http://www.example.net'}) == 'http://www.example.net/?foo=bar'
|
186 |
195 |
assert get_variadic_url('[url]?foo=bar',
|
... | ... | |
201 |
210 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net//?foo=bar'
|
202 |
211 |
|
203 |
212 |
|
204 |
|
def test_url_server_more():
|
|
213 |
def test_url_server_more(pub):
|
205 |
214 |
assert get_variadic_url('[url]/foobar/json?toto',
|
206 |
215 |
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/json?toto'
|
207 |
216 |
assert get_variadic_url('[url]/foobar/json?toto',
|
... | ... | |
218 |
227 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/json?toto'
|
219 |
228 |
|
220 |
229 |
|
221 |
|
def test_url_server_even_more():
|
|
230 |
def test_url_server_even_more(pub):
|
222 |
231 |
assert get_variadic_url('[url]/foobar/json?foo=bar',
|
223 |
232 |
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/json?foo=bar'
|
224 |
233 |
assert get_variadic_url('[url]/foobar/json?foo=bar',
|
... | ... | |
235 |
244 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/json?foo=bar'
|
236 |
245 |
|
237 |
246 |
|
238 |
|
def test_url_server_even_more_more():
|
|
247 |
def test_url_server_even_more_more(pub):
|
239 |
248 |
assert get_variadic_url('[url]/foobar/baz/json?foo=bar',
|
240 |
249 |
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/baz/json?foo=bar'
|
241 |
250 |
assert get_variadic_url('[url]/foobar/baz/json?foo=bar',
|
... | ... | |
252 |
261 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/baz/json?foo=bar'
|
253 |
262 |
|
254 |
263 |
|
255 |
|
def test_url_whole_with_qs():
|
|
264 |
def test_url_whole_with_qs(pub):
|
256 |
265 |
assert get_variadic_url('[url]',
|
257 |
266 |
{'url': 'http://www.example.net/?foo=bar'}) == 'http://www.example.net/?foo=bar'
|
258 |
267 |
|
... | ... | |
260 |
269 |
{'url': 'http://www.example.net/?foo=bar'}) == 'http://www.example.net/?foo=bar'
|
261 |
270 |
|
262 |
271 |
|
263 |
|
def test_url_whole_with_qs_2():
|
|
272 |
def test_url_whole_with_qs_2(pub):
|
264 |
273 |
for url in ('[url]?bar=foo', '[url]&bar=foo', '[url]/?bar=foo'):
|
265 |
274 |
assert get_variadic_url(url, {'url': 'http://www.example.net/?foo=bar'}) in \
|
266 |
275 |
('http://www.example.net/?bar=foo&foo=bar', 'http://www.example.net/?foo=bar&bar=foo')
|
... | ... | |
274 |
283 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/?bar=foo'
|
275 |
284 |
|
276 |
285 |
|
277 |
|
def test_path_missing_var():
|
|
286 |
def test_path_missing_var(pub):
|
278 |
287 |
assert get_variadic_url('http://www.example.net/foobar/[path]',
|
279 |
288 |
{}) == 'http://www.example.net/foobar/[path]'
|
280 |
289 |
|
... | ... | |
283 |
292 |
{}) == 'http://www.example.net/foobar/'
|
284 |
293 |
|
285 |
294 |
|
286 |
|
def test_url_base_and_missing_var():
|
|
295 |
def test_url_base_and_missing_var(pub):
|
287 |
296 |
assert get_variadic_url('[url]/foobar/[path]',
|
288 |
297 |
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/[path]'
|
289 |
298 |
assert get_variadic_url('[url]foobar/[path]',
|
... | ... | |
294 |
303 |
assert get_variadic_url('{{ url }}foobar/{{ path }}',
|
295 |
304 |
{'url': 'http://www.example.net/'}) == 'http://www.example.net/foobar/'
|
296 |
305 |
|
297 |
|
def test_url_bad_syntax():
|
|
306 |
def test_url_bad_syntax(pub):
|
298 |
307 |
with pytest.raises(EZTException):
|
299 |
308 |
get_variadic_url('[if-any form_avr]https://example.net/[foo]/', {'foo': 'bar'})
|
300 |
309 |
|