test_queryparams.py
This file
Path
tests/models/test_queryparams.py
84 lines · 2.2 KiB · Python
Last changed by
Preserve list type query paramaters when merging QueryParams objects (#546) (#547)Caseybefore adoption9df76cc
History of this fileTake it
The walk stopped after 200 commits: lines older than 23f11aa point at it.
Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea
lines 1–2why, one step back1import pytest2Use chained comparison in status codes for error and successSaugat Pachhaibefore adoption23f11aa
lines 3–5why, one step back3from httpx import QueryParams45Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea
lines 6–15why, one step back6@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},12 ],13)14def test_queryparams(source):15 q = QueryParams(source)Use chained comparison in status codes for error and successSaugat Pachhaibefore adoption23f11aa
lines 16–63why, one step back16 assert "a" in q17 assert "A" not in q18 assert "c" not in q19 assert q["a"] == "456"20 assert q.get("a") == "456"21 assert q.get("nope", default=None) is None22 assert q.getlist("a") == ["123", "456"]23 assert list(q.keys()) == ["a", "b"]24 assert list(q.values()) == ["456", "789"]25 assert list(q.items()) == [("a", "456"), ("b", "789")]26 assert len(q) == 227 assert list(q) == ["a", "b"]28 assert dict(q) == {"a": "456", "b": "789"}29 assert str(q) == "a=123&a=456&b=789"30 assert repr(q) == "QueryParams('a=123&a=456&b=789')"31 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(32 [("a", "123"), ("b", "456")]33 )34 assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")35 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(36 {"b": "456", "a": "123"}37 )38 assert QueryParams() == QueryParams({})39 assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")40 assert QueryParams({"a": "123", "b": "456"}) != "invalid"4142 q = QueryParams([("a", "123"), ("a", "456")])43 assert QueryParams(q) == q444546def test_queryparam_types():47 q = QueryParams({"a": True})48 assert str(q) == "a=true"4950 q = QueryParams({"a": False})51 assert str(q) == "a=false"5253 q = QueryParams({"a": ""})54 assert str(q) == "a="5556 q = QueryParams({"a": None})57 assert str(q) == "a="5859 q = QueryParams({"a": 1.23})60 assert str(q) == "a=1.23"6162 q = QueryParams({"a": 123})63 assert str(q) == "a=123"Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
line 64why, one step back64Preserve list type query paramaters when merging QueryParams objects (#546) (#547)Caseybefore adoption9df76cc
lines 65–66why, one step back65 q = QueryParams({"a": [1, 2]})66 assert str(q) == "a=1&a=2"Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
line 67why, one step back67Preserve list type query paramaters when merging QueryParams objects (#546) (#547)Caseybefore adoption9df76cc
line 68why, one step back68Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
lines 69–77why, one step back69def test_queryparam_setters():70 q = QueryParams({"a": 1})71 q.update([])7273 assert str(q) == "a=1"7475 q = QueryParams([("a", 1), ("a", 2)])76 q["a"] = "3"77 assert str(q) == "a=3"Preserve list type query paramaters when merging QueryParams objects (#546) (#547)Caseybefore adoption9df76cc
lines 78–84why, one step back7879 q = QueryParams([("a", 1), ("b", 1)])80 u = QueryParams([("b", 2), ("b", 3)])81 q.update(u)8283 assert str(q) == "a=1&b=2&b=3"84 assert q["b"] == u["b"]