def test_concatenation(): assert URL(b"/") + URL(b"/") == URL(b"/") assert URL(b"https://world-cats.eu") + URL(b"/api/cats") == URL( b"https://world-cats.eu/api/cats" ) assert URL(b"https://world-cats.eu/") + URL(b"/api/cats") == URL( b"https://world-cats.eu/api/cats" )
def test_request_can_update_url(initial_url, new_url): request = Request("GET", initial_url, None) assert request.url.value == initial_url request.url = URL(new_url) assert request.url.value == new_url
def test_relative_url(): url = URL(b"/api/cat/001?foo=power&hello=world") assert url.path == b"/api/cat/001" assert url.schema is None assert url.host is None assert url.port == 0 assert url.query == b"foo=power&hello=world" assert url.fragment is None assert url.is_absolute is False
def test_absolute_url(): url = URL(b"https://robertoprevato.github.io?foo=power&hello=world") assert url.path is None assert url.schema == b"https" assert url.host == b"robertoprevato.github.io" assert url.port == 0 assert url.query == b"foo=power&hello=world" assert url.fragment is None assert url.is_absolute is True
def test_empty_url(): url = URL(b'') assert url.path is None assert url.schema is None assert url.host is None assert url.port == 0 assert url.query is None assert url.fragment is None assert url.userinfo is None assert url.is_absolute is False
def test_absolute_url(): url = URL(b'https://robertoprevato.github.io?foo=power&hello=world') assert url.path is None assert url.schema == b'https' assert url.host == b'robertoprevato.github.io' assert url.port == 0 assert url.query == b'foo=power&hello=world' assert url.fragment is None assert url.userinfo is None assert url.is_absolute is True
def test_relative_url(): url = URL(b'/api/cat/001?foo=power&hello=world') assert url.path == b'/api/cat/001' assert url.schema is None assert url.host is None assert url.port == 0 assert url.query == b'foo=power&hello=world' assert url.fragment is None assert url.userinfo is None assert url.is_absolute is False
def test_base_url(value, expected_base_url): url = URL(value) base_url = url.base_url() assert expected_base_url == base_url.value
def test_cannot_concatenate_absolute_urls(): with pytest.raises(ValueError): URL(b"https://world-cats.eu") + URL(b"https://hello-world") with pytest.raises(ValueError): URL(b"http://world-cats.eu") + URL(b"http://hello-world")
def test_cannot_concatenate_one_url_first_with_query_or_path(): with pytest.raises(ValueError): URL(b"https://world-cats.eu?hello=world") + URL(b"/api/cats") with pytest.raises(ValueError): URL(b"http://world-cats.eu/#/about") + URL(b"/api/cats")
def test_empty_url(): with pytest.raises(InvalidURL): URL(b"")
def test_cannot_instantiate_relative_url_without_trailing_slash(): # otherwise, we could not distinguish between a URL and a URN redirect with pytest.raises(InvalidURL): URL(b'api/cat/001?foo=power&hello=world')
def test_equality(): assert URL(b"/") == URL(b"/") assert URL(b"/api/cats") == URL(b"/api/cats") assert URL(b"/api/cats") != URL(b"/api/cat/001")
def test_equality(): assert URL(b'') == URL(b'') assert URL(b'/api/cats') == URL(b'/api/cats') assert URL(b'/api/cats') != URL(b'/api/cat/001')
def test_raises_for_invalid_scheme(): with pytest.raises(InvalidURL): URL(b"file://D:/a/b/c")
def test_concatenation(): assert URL(b'') + URL(b'') == URL(b'') assert URL(b'https://world-cats.eu') + URL(b'/api/cats') == URL( b'https://world-cats.eu/api/cats') assert URL(b'https://world-cats.eu/') + URL(b'/api/cats') == URL( b'https://world-cats.eu/api/cats')
async def test_request_url_binder(url): request = Request("GET", url, []) parameter = RequestURLBinder() value = await parameter.get_value(request) assert value == URL(url)