Skip to content
Myr

test_url.py

This file

Path

tests/models/test_url.py

50 lines · 1.5 KiB · Python

Last changed by

Allow string comparison for URL().__eq__ (#139)Stephen Brown IIbefore adoption8db36ed

History of this file

Take it

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 1why, one step back
1from httpx import URL

Add idna support. More tests.Tom Christiebefore adoptionb948798

lines 2–7why, one step back
2
34def test_idna_url():5 url = URL("http://中国.icom.museum:80/")6 assert url == URL("http://xn--fiqs8s.icom.museum:80/")7 assert url.host == "xn--fiqs8s.icom.museum"

Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36

lines 8–18why, one step back
8
910def test_url():11 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")12 assert url.scheme == "https"13 assert url.host == "example.org"14 assert url.port == 12315 assert url.authority == "example.org:123"16 assert url.path == "/path/to/somewhere"17 assert url.query == "abc=123"18 assert url.fragment == "anchor"

Truckin' onTom Christiebefore adoption0ca1c84

lines 19–21why, one step back
19 assert (
20 repr(url) == "URL('https://example.org:123/path/to/somewhere?abc=123#anchor')"21 )

Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36

lines 22–25why, one step back
22
23 new = url.copy_with(scheme="http")24 assert new == URL("http://example.org:123/path/to/somewhere?abc=123#anchor")25 assert new.scheme == "http"

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 26–27why, one step back
26
27

Allow string comparison for URL().__eq__ (#139)Stephen Brown IIbefore adoption8db36ed

lines 28–33why, one step back
28def test_url_eq_str():
29 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")30 assert url == "https://example.org:123/path/to/somewhere?abc=123#anchor"31 assert str(url) == url3233

query_params -> paramsTom Christiebefore adoptionbb70377

lines 34–35why, one step back
34def test_url__params():
35 url = URL("https://example.org:123/path/to/somewhere", params={"a": "123"})

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 36–37why, one step back
36 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"
37

query_params -> paramsTom Christiebefore adoptionbb70377

line 38why, one step back
38 url = URL("https://example.org:123/path/to/somewhere?b=456", params={"a": "123"})

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 39why, one step back
39 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"

Include URL.__hash__ in test (#64)Yeray Diaz Diazbefore adoption2e9ab2e

lines 40–50why, one step back
40
4142def test_url_set():43 urls = (44 URL("http://example.org:123/path/to/somewhere"),45 URL("http://example.org:123/path/to/somewhere/else"),46 )4748 url_set = set(urls)4950 assert all(url in urls for url in url_set)