test_url.py
This file
Path
tests/models/test_url.py
192 lines · 6.3 KiB · Python
Last changed by
Implement HTTPProxy dispatcher (#259)Seth Michael Larsonbefore adoption57c27ca
History of this fileTake it
The walk stopped after 200 commits: lines older than 33a2249 point at it.
Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b
lines 1–2why, one step back1import pytest2Add test for origin from URL string (#312)Yeray Diaz Diazbefore adoptionfa74aaa
line 3why, one step back3from httpx import URL, OriginFix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb
line 4why, one step back4from httpx.exceptions import InvalidURLTweakTom Christiebefore adoption33a2249
lines 5–6why, one step back56Update IDNA encoding to 2008 spec (#161)Stephen Brown IIbefore adoption40849bf
lines 7–61why, one step back7@pytest.mark.parametrize(8 "given,idna,host,scheme,port",9 [10 (11 "http://中国.icom.museum:80/",12 "http://xn--fiqs8s.icom.museum:80/",13 "xn--fiqs8s.icom.museum",14 "http",15 80,16 ),17 (18 "http://Königsgäßchen.de",19 "http://xn--knigsgchen-b4a3dun.de",20 "xn--knigsgchen-b4a3dun.de",21 "http",22 80,23 ),24 ("https://faß.de", "https://xn--fa-hia.de", "xn--fa-hia.de", "https", 443),25 (26 "https://βόλος.com:443",27 "https://xn--nxasmm1c.com:443",28 "xn--nxasmm1c.com",29 "https",30 443,31 ),32 (33 "http://ශ්රී.com:444",34 "http://xn--10cl1a0b660p.com:444",35 "xn--10cl1a0b660p.com",36 "http",37 444,38 ),39 (40 "https://نامهای.com:4433",41 "https://xn--mgba3gch31f060k.com:4433",42 "xn--mgba3gch31f060k.com",43 "https",44 4433,45 ),46 ],47 ids=[48 "http_with_port",49 "unicode_tr46_compat",50 "https_without_port",51 "https_with_port",52 "http_with_custom_port",53 "https_with_custom_port",54 ],55)56def test_idna_url(given, idna, host, scheme, port):57 url = URL(given)58 assert url == URL(idna)59 assert url.host == host60 assert url.scheme == scheme61 assert url.port == portTweakTom Christiebefore adoption33a2249
lines 62–81why, one step back626364def test_url():65 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")66 assert url.scheme == "https"67 assert url.host == "example.org"68 assert url.port == 12369 assert url.authority == "example.org:123"70 assert url.path == "/path/to/somewhere"71 assert url.query == "abc=123"72 assert url.fragment == "anchor"73 assert (74 repr(url) == "URL('https://example.org:123/path/to/somewhere?abc=123#anchor')"75 )7677 new = url.copy_with(scheme="http")78 assert new == URL("http://example.org:123/path/to/somewhere?abc=123#anchor")79 assert new.scheme == "http"8081Allow string comparison for URL().__eq__ (#139)Stephen Brown IIbefore adoption8db36ed
lines 82–87why, one step back82def test_url_eq_str():83 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")84 assert url == "https://example.org:123/path/to/somewhere?abc=123#anchor"85 assert str(url) == url8687Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb
line 88why, one step back88def test_url_params():TweakTom Christiebefore adoption33a2249
lines 89–93why, one step back89 url = URL("https://example.org:123/path/to/somewhere", params={"a": "123"})90 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"9192 url = URL("https://example.org:123/path/to/somewhere?b=456", params={"a": "123"})93 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb
lines 94–100why, one step back949596def test_url_join():97 """98 Some basic URL joining tests.99 """100 url = URL("https://example.org:123/path/to/somewhere")Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b
lines 101–108why, one step back101 assert url.join("/somewhere-else") == "https://example.org:123/somewhere-else"102 assert (103 url.join("somewhere-else") == "https://example.org:123/path/to/somewhere-else"104 )105 assert (106 url.join("../somewhere-else") == "https://example.org:123/path/somewhere-else"107 )108 assert url.join("../../somewhere-else") == "https://example.org:123/somewhere-else"Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb
lines 109–166why, one step back109110111def test_url_join_rfc3986():112 """113 URL joining tests, as-per reference examples in RFC 3986.114115 https://tools.ietf.org/html/rfc3986#section-5.4116 """117118 url = URL("http://example.com/b/c/d;p?q")119120 with pytest.raises(InvalidURL):121 assert url.join("g:h") == "g:h"122123 assert url.join("g") == "http://example.com/b/c/g"124 assert url.join("./g") == "http://example.com/b/c/g"125 assert url.join("g/") == "http://example.com/b/c/g/"126 assert url.join("/g") == "http://example.com/g"127 assert url.join("//g") == "http://g"128 assert url.join("?y") == "http://example.com/b/c/d;p?y"129 assert url.join("g?y") == "http://example.com/b/c/g?y"130 assert url.join("#s") == "http://example.com/b/c/d;p?q#s"131 assert url.join("g#s") == "http://example.com/b/c/g#s"132 assert url.join("g?y#s") == "http://example.com/b/c/g?y#s"133 assert url.join(";x") == "http://example.com/b/c/;x"134 assert url.join("g;x") == "http://example.com/b/c/g;x"135 assert url.join("g;x?y#s") == "http://example.com/b/c/g;x?y#s"136 assert url.join("") == "http://example.com/b/c/d;p?q"137 assert url.join(".") == "http://example.com/b/c/"138 assert url.join("./") == "http://example.com/b/c/"139 assert url.join("..") == "http://example.com/b/"140 assert url.join("../") == "http://example.com/b/"141 assert url.join("../g") == "http://example.com/b/g"142 assert url.join("../..") == "http://example.com/"143 assert url.join("../../") == "http://example.com/"144 assert url.join("../../g") == "http://example.com/g"145146 assert url.join("../../../g") == "http://example.com/g"147 assert url.join("../../../../g") == "http://example.com/g"148149 assert url.join("/./g") == "http://example.com/g"150 assert url.join("/../g") == "http://example.com/g"151 assert url.join("g.") == "http://example.com/b/c/g."152 assert url.join(".g") == "http://example.com/b/c/.g"153 assert url.join("g..") == "http://example.com/b/c/g.."154 assert url.join("..g") == "http://example.com/b/c/..g"155156 assert url.join("./../g") == "http://example.com/b/g"157 assert url.join("./g/.") == "http://example.com/b/c/g/"158 assert url.join("g/./h") == "http://example.com/b/c/g/h"159 assert url.join("g/../h") == "http://example.com/b/c/h"160 assert url.join("g;x=1/./y") == "http://example.com/b/c/g;x=1/y"161 assert url.join("g;x=1/../y") == "http://example.com/b/c/y"162163 assert url.join("g?y/./x") == "http://example.com/b/c/g?y/./x"164 assert url.join("g?y/../x") == "http://example.com/b/c/g?y/../x"165 assert url.join("g#s/./x") == "http://example.com/b/c/g#s/./x"166 assert url.join("g#s/../x") == "http://example.com/b/c/g#s/../x"TweakTom Christiebefore adoption33a2249
lines 167–177why, one step back167168169def test_url_set():170 urls = (171 URL("http://example.org:123/path/to/somewhere"),172 URL("http://example.org:123/path/to/somewhere/else"),173 )174175 url_set = set(urls)176177 assert all(url in urls for url in url_set)Add test for origin from URL string (#312)Yeray Diaz Diazbefore adoptionfa74aaa
lines 178–179why, one step back178179Implement HTTPProxy dispatcher (#259)Seth Michael Larsonbefore adoption57c27ca
lines 180–186why, one step back180def test_url_full_path_setter():181 url = URL("http://example.org")182183 url.full_path = "http://example.net"184 assert url.full_path == "http://example.net"185186Add test for origin from URL string (#312)Yeray Diaz Diazbefore adoptionfa74aaa
lines 187–192why, one step back187def test_origin_from_url_string():188 origin = Origin("https://example.com")189 assert origin.scheme == "https"190 assert origin.is_ssl191 assert origin.host == "example.com"192 assert origin.port == 443