test_queryparams.py
This file
Path
tests/models/test_queryparams.py
53 lines · 1.6 KiB · Python
Last changed by
Tweak query param types (#175)Tom Christiebefore adoption66754ad
History of this fileTake it
Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 1why, one step back1from httpx import QueryParamsMerge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
lines 2–33why, one step back234def test_queryparams():5 q = QueryParams("a=123&a=456&b=789")6 assert "a" in q7 assert "A" not in q8 assert "c" not in q9 assert q["a"] == "456"10 assert q.get("a") == "456"11 assert q.get("nope", default=None) is None12 assert q.getlist("a") == ["123", "456"]13 assert list(q.keys()) == ["a", "b"]14 assert list(q.values()) == ["456", "789"]15 assert list(q.items()) == [("a", "456"), ("b", "789")]16 assert len(q) == 217 assert list(q) == ["a", "b"]18 assert dict(q) == {"a": "456", "b": "789"}19 assert str(q) == "a=123&a=456&b=789"20 assert repr(q) == "QueryParams('a=123&a=456&b=789')"21 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(22 [("a", "123"), ("b", "456")]23 )24 assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")25 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(26 {"b": "456", "a": "123"}27 )28 assert QueryParams() == QueryParams({})29 assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")30 assert QueryParams({"a": "123", "b": "456"}) != "invalid"3132 q = QueryParams([("a", "123"), ("a", "456")])33 assert QueryParams(q) == qTweak query param types (#175)Tom Christiebefore adoption66754ad
lines 34–53why, one step back343536def test_queryparam_types():37 q = QueryParams({"a": True})38 assert str(q) == "a=true"3940 q = QueryParams({"a": False})41 assert str(q) == "a=false"4243 q = QueryParams({"a": ""})44 assert str(q) == "a="4546 q = QueryParams({"a": None})47 assert str(q) == "a="4849 q = QueryParams({"a": 1.23})50 assert str(q) == "a=1.23"5152 q = QueryParams({"a": 123})53 assert str(q) == "a=123"