Skip to content
Myr

test_url.py

This file

Path

tests/models/test_url.py

134 lines · 4.9 KiB · Python

Last changed by

Switch hosts on HSTS preload to HTTPS (#151)Seth Michael Larsonbefore adoption3ba2e8c

History of this file

Take it

Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b

lines 1–2why, one step back
1import pytest
2

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb

line 4why, one step back
4from httpx.exceptions import InvalidURL

Add idna support. More tests.Tom Christiebefore adoptionb948798

lines 5–10why, one step back
5
67def test_idna_url():8 url = URL("http://中国.icom.museum:80/")9 assert url == URL("http://xn--fiqs8s.icom.museum:80/")10 assert url.host == "xn--fiqs8s.icom.museum"

Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36

lines 11–21why, one step back
11
1213def test_url():14 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")15 assert url.scheme == "https"16 assert url.host == "example.org"17 assert url.port == 12318 assert url.authority == "example.org:123"19 assert url.path == "/path/to/somewhere"20 assert url.query == "abc=123"21 assert url.fragment == "anchor"

Truckin' onTom Christiebefore adoption0ca1c84

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

Carefulness with encoding everywhereTom Christiebefore adoptione1ecb36

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

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

lines 29–30why, one step back
29
30

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

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

Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb

line 37why, one step back
37def test_url_params():

query_params -> paramsTom Christiebefore adoptionbb70377

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

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

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

query_params -> paramsTom Christiebefore adoptionbb70377

line 41why, one step back
41 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 42why, one step back
42 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"

Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb

lines 43–49why, one step back
43
4445def test_url_join():46 """47 Some basic URL joining tests.48 """49 url = URL("https://example.org:123/path/to/somewhere")

Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b

lines 50–57why, one step back
50 assert url.join("/somewhere-else") == "https://example.org:123/somewhere-else"
51 assert (52 url.join("somewhere-else") == "https://example.org:123/path/to/somewhere-else"53 )54 assert (55 url.join("../somewhere-else") == "https://example.org:123/path/somewhere-else"56 )57 assert url.join("../../somewhere-else") == "https://example.org:123/somewhere-else"

Fix `URL.join(...)` (#144)Tom Christiebefore adoption00e4fdb

lines 58–115why, one step back
58
5960def test_url_join_rfc3986():61 """62 URL joining tests, as-per reference examples in RFC 3986.6364 https://tools.ietf.org/html/rfc3986#section-5.465 """6667 url = URL("http://example.com/b/c/d;p?q")6869 with pytest.raises(InvalidURL):70 assert url.join("g:h") == "g:h"7172 assert url.join("g") == "http://example.com/b/c/g"73 assert url.join("./g") == "http://example.com/b/c/g"74 assert url.join("g/") == "http://example.com/b/c/g/"75 assert url.join("/g") == "http://example.com/g"76 assert url.join("//g") == "http://g"77 assert url.join("?y") == "http://example.com/b/c/d;p?y"78 assert url.join("g?y") == "http://example.com/b/c/g?y"79 assert url.join("#s") == "http://example.com/b/c/d;p?q#s"80 assert url.join("g#s") == "http://example.com/b/c/g#s"81 assert url.join("g?y#s") == "http://example.com/b/c/g?y#s"82 assert url.join(";x") == "http://example.com/b/c/;x"83 assert url.join("g;x") == "http://example.com/b/c/g;x"84 assert url.join("g;x?y#s") == "http://example.com/b/c/g;x?y#s"85 assert url.join("") == "http://example.com/b/c/d;p?q"86 assert url.join(".") == "http://example.com/b/c/"87 assert url.join("./") == "http://example.com/b/c/"88 assert url.join("..") == "http://example.com/b/"89 assert url.join("../") == "http://example.com/b/"90 assert url.join("../g") == "http://example.com/b/g"91 assert url.join("../..") == "http://example.com/"92 assert url.join("../../") == "http://example.com/"93 assert url.join("../../g") == "http://example.com/g"9495 assert url.join("../../../g") == "http://example.com/g"96 assert url.join("../../../../g") == "http://example.com/g"9798 assert url.join("/./g") == "http://example.com/g"99 assert url.join("/../g") == "http://example.com/g"100 assert url.join("g.") == "http://example.com/b/c/g."101 assert url.join(".g") == "http://example.com/b/c/.g"102 assert url.join("g..") == "http://example.com/b/c/g.."103 assert url.join("..g") == "http://example.com/b/c/..g"104105 assert url.join("./../g") == "http://example.com/b/g"106 assert url.join("./g/.") == "http://example.com/b/c/g/"107 assert url.join("g/./h") == "http://example.com/b/c/g/h"108 assert url.join("g/../h") == "http://example.com/b/c/h"109 assert url.join("g;x=1/./y") == "http://example.com/b/c/g;x=1/y"110 assert url.join("g;x=1/../y") == "http://example.com/b/c/y"111112 assert url.join("g?y/./x") == "http://example.com/b/c/g?y/./x"113 assert url.join("g?y/../x") == "http://example.com/b/c/g?y/../x"114 assert url.join("g#s/./x") == "http://example.com/b/c/g#s/./x"115 assert url.join("g#s/../x") == "http://example.com/b/c/g#s/../x"

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

lines 116–126why, one step back
116
117118def test_url_set():119 urls = (120 URL("http://example.org:123/path/to/somewhere"),121 URL("http://example.org:123/path/to/somewhere/else"),122 )123124 url_set = set(urls)125126 assert all(url in urls for url in url_set)

Switch hosts on HSTS preload to HTTPS (#151)Seth Michael Larsonbefore adoption3ba2e8c

lines 127–134why, one step back
127
128129def test_hsts_preload_converted_to_https():130 url = URL("http://www.paypal.com")131132 assert url.is_ssl133 assert url.scheme == "https"134 assert url == "https://www.paypal.com"