-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_queryparams.py
More file actions
87 lines (68 loc) · 2.22 KB
/
test_queryparams.py
File metadata and controls
87 lines (68 loc) · 2.22 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
import pytest
from httpx import QueryParams
@pytest.mark.parametrize(
"source",
[
"a=123&a=456&b=789",
{"a": ["123", "456"], "b": 789},
{"a": ("123", "456"), "b": 789},
],
)
def test_queryparams(source):
q = QueryParams(source)
assert "a" in q
assert "A" not in q
assert "c" not in q
assert q["a"] == "456"
assert q.get("a") == "456"
assert q.get("nope", default=None) is None
assert q.getlist("a") == ["123", "456"]
assert list(q.keys()) == ["a", "b"]
assert list(q.values()) == ["456", "789"]
assert list(q.items()) == [("a", "456"), ("b", "789")]
assert len(q) == 2
assert list(q) == ["a", "b"]
assert dict(q) == {"a": "456", "b": "789"}
assert str(q) == "a=123&a=456&b=789"
assert repr(q) == "QueryParams('a=123&a=456&b=789')"
assert QueryParams({"a": "123", "b": "456"}) == QueryParams(
[("a", "123"), ("b", "456")]
)
assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")
assert QueryParams({"a": "123", "b": "456"}) == QueryParams(
{"b": "456", "a": "123"}
)
assert QueryParams() == QueryParams({})
assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")
assert QueryParams({"a": "123", "b": "456"}) != "invalid"
q = QueryParams([("a", "123"), ("a", "456")])
assert QueryParams(q) == q
def test_queryparam_types():
q = QueryParams(None)
assert str(q) == ""
q = QueryParams({"a": True})
assert str(q) == "a=true"
q = QueryParams({"a": False})
assert str(q) == "a=false"
q = QueryParams({"a": ""})
assert str(q) == "a="
q = QueryParams({"a": None})
assert str(q) == "a="
q = QueryParams({"a": 1.23})
assert str(q) == "a=1.23"
q = QueryParams({"a": 123})
assert str(q) == "a=123"
q = QueryParams({"a": [1, 2]})
assert str(q) == "a=1&a=2"
def test_queryparam_setters():
q = QueryParams({"a": 1})
q.update([])
assert str(q) == "a=1"
q = QueryParams([("a", 1), ("a", 2)])
q["a"] = "3"
assert str(q) == "a=3"
q = QueryParams([("a", 1), ("b", 1)])
u = QueryParams([("b", 2), ("b", 3)])
q.update(u)
assert str(q) == "a=1&b=2&b=3"
assert q["b"] == u["b"]