test_queryparams.py
This file
Path
tests/models/test_queryparams.py
74 lines · 1.9 KiB · Python
Last changed by
Allow lists in query params (#386)Florimond Mancabefore adoption57ae7ea
History of this fileTake it
1import pytest23from httpx import QueryParams456@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)16 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"646566def test_queryparam_setters():67 q = QueryParams({"a": 1})68 q.update([])6970 assert str(q) == "a=1"7172 q = QueryParams([("a", 1), ("a", 2)])73 q["a"] = "3"74 assert str(q) == "a=3"