Example #1
0
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"
    )
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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
Example #8
0
def test_base_url(value, expected_base_url):
    url = URL(value)
    base_url = url.base_url()
    assert expected_base_url == base_url.value
Example #9
0
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")
Example #10
0
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")
Example #11
0
def test_empty_url():
    with pytest.raises(InvalidURL):
        URL(b"")
Example #12
0
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')
Example #13
0
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")
Example #14
0
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')
Example #15
0
def test_raises_for_invalid_scheme():

    with pytest.raises(InvalidURL):
        URL(b"file://D:/a/b/c")
Example #16
0
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')
Example #17
0
async def test_request_url_binder(url):
    request = Request("GET", url, [])
    parameter = RequestURLBinder()
    value = await parameter.get_value(request)
    assert value == URL(url)