Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_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_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_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_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_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():
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.is_absolute is False
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_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