test_queryparams.py
This file
Path
tests/models/test_queryparams.py
92 lines · 2.4 KiB · Python
Last changed by
Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
History of this fileTake it
1import pytest23import 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},12 ],13)14def test_queryparams(source):15 q = httpx.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.get_list("a") == ["123", "456"]2324 assert list(q.keys()) == ["a", "b"]25 assert list(q.values()) == ["456", "789"]26 assert list(q.items()) == [("a", "456"), ("b", "789")]27 assert len(q) == 228 assert list(q) == ["a", "b"]29 assert dict(q) == {"a": "456", "b": "789"}30 assert str(q) == "a=123&a=456&b=789"31 assert repr(q) == "QueryParams('a=123&a=456&b=789')"32 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(33 [("a", "123"), ("b", "456")]34 )35 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(36 "a=123&b=456"37 )38 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(39 {"b": "456", "a": "123"}40 )41 assert httpx.QueryParams() == httpx.QueryParams({})42 assert httpx.QueryParams([("a", "123"), ("a", "456")]) == httpx.QueryParams(43 "a=123&a=456"44 )45 assert httpx.QueryParams({"a": "123", "b": "456"}) != "invalid"4647 q = httpx.QueryParams([("a", "123"), ("a", "456")])48 assert httpx.QueryParams(q) == q495051def test_queryparam_types():52 q = httpx.QueryParams(None)53 assert str(q) == ""5455 q = httpx.QueryParams({"a": True})56 assert str(q) == "a=true"5758 q = httpx.QueryParams({"a": False})59 assert str(q) == "a=false"6061 q = httpx.QueryParams({"a": ""})62 assert str(q) == "a="6364 q = httpx.QueryParams({"a": None})65 assert str(q) == "a="6667 q = httpx.QueryParams({"a": 1.23})68 assert str(q) == "a=1.23"6970 q = httpx.QueryParams({"a": 123})71 assert str(q) == "a=123"7273 q = httpx.QueryParams({"a": [1, 2]})74 assert str(q) == "a=1&a=2"757677def test_queryparam_setters():78 q = httpx.QueryParams({"a": 1})79 q.update([])8081 assert str(q) == "a=1"8283 q = httpx.QueryParams([("a", 1), ("a", 2)])84 q["a"] = "3"85 assert str(q) == "a=3"8687 q = httpx.QueryParams([("a", 1), ("b", 1)])88 u = httpx.QueryParams([("b", 2), ("b", 3)])89 q.update(u)9091 assert str(q) == "a=1&b=2&b=3"92 assert q["b"] == u["b"]