wcs/tests/test_variadic_url.py

82 lines
4.1 KiB
Python

from wcs.qommon.misc import get_variadic_url
def test_url_unchanged():
assert get_variadic_url('http://www.example.net/foobar', {}) == 'http://www.example.net/foobar'
def test_url_scheme():
assert get_variadic_url('http[https]://www.example.net/foobar',
{'https': 's'}) == 'https://www.example.net/foobar'
assert get_variadic_url('http[https]://www.example.net/foobar',
{'https': ''}) == 'http://www.example.net/foobar'
def test_url_netloc():
assert get_variadic_url('http://[hostname]/foobar',
{'hostname': 'www.example.net'}) == 'http://www.example.net/foobar'
assert get_variadic_url('http://[hostname]/foobar',
{'hostname': 'www.example.com'}) == 'http://www.example.com/foobar'
def test_url_netloc_port():
assert get_variadic_url('http://www.example.net:[port]/foobar',
{'port': '80'}) == 'http://www.example.net:80/foobar'
def test_url_path():
assert get_variadic_url('http://www.example.net/[path]',
{'path': 'foobar'}) == 'http://www.example.net/foobar'
assert get_variadic_url('http://www.example.net/[path]',
{'path': 'foo bar'}) == 'http://www.example.net/foo%20bar'
def test_url_query_variable():
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
{'world': 'world'}) == 'http://www.example.net/foobar?hello=world'
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
{'world': 'a b'}) == 'http://www.example.net/foobar?hello=a+b'
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
{'world': 'a&b'}) == 'http://www.example.net/foobar?hello=a%26b'
assert get_variadic_url('http://www.example.net/foobar?hello=[world]',
{'world': 'a=b'}) == 'http://www.example.net/foobar?hello=a%3Db'
def test_url_query_key():
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
{'hello': 'hello'}) == 'http://www.example.net/foobar?hello=world'
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
{'hello': 'a b'}) == 'http://www.example.net/foobar?a+b=world'
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
{'hello': 'a&b'}) == 'http://www.example.net/foobar?a%26b=world'
assert get_variadic_url('http://www.example.net/foobar?[hello]=world',
{'hello': 'a=b'}) == 'http://www.example.net/foobar?a%3Db=world'
def test_url_query_whole():
assert get_variadic_url('http://www.example.net/foobar?[hello]',
{'hello': 'hello=world'}) == 'http://www.example.net/foobar?hello=world'
def test_url_netloc_port_and_path():
assert get_variadic_url('http://www.example.net:[port]/foobar/[path]',
{'port': '80', 'path': 'baz'}) == 'http://www.example.net:80/foobar/baz'
assert get_variadic_url('http://www.example.net:[port]/foobar/[path]',
{'port': '80', 'path': 'b z'}) == 'http://www.example.net:80/foobar/b%20z'
def test_url_whole():
assert get_variadic_url('[url]',
{'url': 'http://www.example.net/foobar'}) == 'http://www.example.net/foobar'
def test_url_server():
assert get_variadic_url('[url]/foobar',
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar'
def test_url_server_more():
assert get_variadic_url('[url]/foobar/json?toto',
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/json?toto'
def test_url_server_even_more():
assert get_variadic_url('[url]/foobar/json?foo=bar',
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/json?foo=bar'
def test_url_server_even_more_more():
assert get_variadic_url('[url]/foobar/baz/json?foo=bar',
{'url': 'http://www.example.net'}) == 'http://www.example.net/foobar/baz/json?foo=bar'
def test_url_whole_with_qs():
assert get_variadic_url('[url]',
{'url': 'http://www.example.net/?foo=bar'}) == 'http://www.example.net/?foo=bar'