-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_02_components.py
More file actions
88 lines (62 loc) · 2.82 KB
/
test_02_components.py
File metadata and controls
88 lines (62 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import httpx
def test_url():
url = httpx.URL('https://www.example.com/')
assert repr(url) == "<URL 'https://www.example.com/'>"
assert str(url) == "https://www.example.com/"
def test_url_components():
url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")
assert url.scheme == "https"
assert url.username == "jo@email.com"
assert url.password == "a secret"
assert url.userinfo == "jo%40email.com:a%20secret"
assert url.host == "xn--mller-kva.de"
assert url.port == 1234
assert url.netloc == "xn--mller-kva.de:1234"
assert url.path == "/pa th"
assert url.query == "?search=ab"
assert url.fragment == "anchorlink"
def test_url_normalisation():
url = httpx.URL('https://www.EXAMPLE.com:443/path/../main')
assert repr(url) == "<URL 'https://www.example.com/main'>"
assert str(url) == "https://www.example.com/main"
def test_relative_url():
url = httpx.URL('/README.md')
assert repr(url) == "<URL '/README.md'>"
assert str(url) == "/README.md"
def test_url_escape():
url = httpx.URL('https://example.com/path to here?search=🦋')
assert repr(url) == "<URL 'https://example.com/path%20to%20here?search=%F0%9F%A6%8B'>"
assert str(url) == "https://example.com/path%20to%20here?search=%F0%9F%A6%8B"
def test_url_components():
url = httpx.URL(scheme="https", host="example.com", path="/")
assert repr(url) == "<URL 'https://example.com/'>"
assert str(url) == "https://example.com/"
def test_url_params():
url = httpx.URL("https://example.com/", params={"search": "some text"})
assert repr(url) == "<URL 'https://example.com/?search=some+text'>"
assert str(url) == "https://example.com/?search=some+text"
def test_queryparams():
params = httpx.QueryParams({"color": "black", "size": "medium"})
assert repr(params) == "<QueryParams 'color=black&size=medium'>"
assert str(params) == "color=black&size=medium"
def test_queryparams_multi():
params = httpx.QueryParams({"filter": ["60GHz", "75GHz", "100GHz"]})
assert repr(params) == "<QueryParams 'filter=60GHz&filter=75GHz&filter=100GHz'>"
assert str(params) == "filter=60GHz&filter=75GHz&filter=100GHz"
def test_queryparams_keys():
params = httpx.QueryParams("a=123&a=456&b=789")
assert list(params.keys()) == ["a", "b"]
# >>> params = httpx.QueryParams("color=black&size=medium")
# >>> params
# <QueryParams 'color=black&size=medium'>
# >>> params = httpx.QueryParams("sort_by=published&author=natalie")
# >>> params["sort_by"]
# 'published'
# >>> params = httpx.QueryParams({"email": "user@example.com", "search": "How HTTP works!"})
# >>> str(params)
# 'email=user%40example.com&search=How+HTTP+works%21'
# >>> headers = httpx.Headers({"Accept": "*/*"})
# >>> headers
# <Headers {"Accept": "*/*"}>
# >>> headers['accept']
# '*/*'