Skip to content
Myr

test_queryparams.py

This file

Path

tests/models/test_queryparams.py

125 lines · 3.3 KiB · Python

Last changed by

Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2

History of this file

Take it

The walk stopped after 200 commits: lines older than d25f2bf point at it.

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 1–11why, one step back
1import pytest
23import httpx456@pytest.mark.parametrize(7 "source",8 [9 "a=123&a=456&b=789",10 {"a": ["123", "456"], "b": 789},11 {"a": ("123", "456"), "b": 789},

Allow tuple as input of query parameters. (#1426)SarunasAznabefore adoption8696405

lines 12–13why, one step back
12 [("a", "123"), ("a", "456"), ("b", "789")],
13 (("a", "123"), ("a", "456"), ("b", "789")),

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 14–20why, one step back
14 ],
15)16def test_queryparams(source):17 q = httpx.QueryParams(source)18 assert "a" in q19 assert "A" not in q20 assert "c" not in q

Tweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5

lines 21–22why, one step back
21 assert q["a"] == "123"
22 assert q.get("a") == "123"

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 23–26why, one step back
23 assert q.get("nope", default=None) is None
24 assert q.get_list("a") == ["123", "456"]2526 assert list(q.keys()) == ["a", "b"]

Tweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5

lines 27–28why, one step back
27 assert list(q.values()) == ["123", "789"]
28 assert list(q.items()) == [("a", "123"), ("b", "789")]

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 29–30why, one step back
29 assert len(q) == 2
30 assert list(q) == ["a", "b"]

Tweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5

line 31why, one step back
31 assert dict(q) == {"a": "123", "b": "789"}

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 32–78why, one step back
32 assert str(q) == "a=123&a=456&b=789"
33 assert repr(q) == "QueryParams('a=123&a=456&b=789')"34 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(35 [("a", "123"), ("b", "456")]36 )37 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(38 "a=123&b=456"39 )40 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(41 {"b": "456", "a": "123"}42 )43 assert httpx.QueryParams() == httpx.QueryParams({})44 assert httpx.QueryParams([("a", "123"), ("a", "456")]) == httpx.QueryParams(45 "a=123&a=456"46 )47 assert httpx.QueryParams({"a": "123", "b": "456"}) != "invalid"4849 q = httpx.QueryParams([("a", "123"), ("a", "456")])50 assert httpx.QueryParams(q) == q515253def test_queryparam_types():54 q = httpx.QueryParams(None)55 assert str(q) == ""5657 q = httpx.QueryParams({"a": True})58 assert str(q) == "a=true"5960 q = httpx.QueryParams({"a": False})61 assert str(q) == "a=false"6263 q = httpx.QueryParams({"a": ""})64 assert str(q) == "a="6566 q = httpx.QueryParams({"a": None})67 assert str(q) == "a="6869 q = httpx.QueryParams({"a": 1.23})70 assert str(q) == "a=1.23"7172 q = httpx.QueryParams({"a": 123})73 assert str(q) == "a=123"7475 q = httpx.QueryParams({"a": [1, 2]})76 assert str(q) == "a=1&a=2"7778

Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2

lines 79–82why, one step back
79def test_queryparam_update_is_hard_deprecated():
80 q = httpx.QueryParams("a=123")81 with pytest.raises(RuntimeError):82 q.update({"a": "456"})

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 83–84why, one step back
83
84

Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2

lines 85–88why, one step back
85def test_queryparam_setter_is_hard_deprecated():
86 q = httpx.QueryParams("a=123")87 with pytest.raises(RuntimeError):88 q["a"] = "456"

Fix stream unsetting auth (#1312)Tom Christiebefore adoptiond25f2bf

lines 89–90why, one step back
89
90

Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2

lines 91–125why, one step back
91def test_queryparam_set():
92 q = httpx.QueryParams("a=123")93 q = q.set("a", "456")94 assert q == httpx.QueryParams("a=456")959697def test_queryparam_add():98 q = httpx.QueryParams("a=123")99 q = q.add("a", "456")100 assert q == httpx.QueryParams("a=123&a=456")101102103def test_queryparam_remove():104 q = httpx.QueryParams("a=123")105 q = q.remove("a")106 assert q == httpx.QueryParams("")107108109def test_queryparam_merge():110 q = httpx.QueryParams("a=123")111 q = q.merge({"b": "456"})112 assert q == httpx.QueryParams("a=123&b=456")113 q = q.merge({"a": "000", "c": "789"})114 assert q == httpx.QueryParams("a=000&b=456&c=789")115116117def test_queryparams_are_hashable():118 params = (119 httpx.QueryParams("a=123"),120 httpx.QueryParams({"a": 123}),121 httpx.QueryParams("b=456"),122 httpx.QueryParams({"b": 456}),123 )124125 assert len(set(params)) == 2