Skip to content
Myr

test_queryparams.py

This file

Path

tests/models/test_queryparams.py

91 lines · 2.3 KiB · Python

Last changed by

Use get_list consistently (#1119)Tom Christiebefore adoptione5f8743

History of this file

Take it

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

Update link to timeout fine tuning in quickstart (#696)David Larletbefore adoption22663bc

lines 1–21why, one step back
1import pytest
23from 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 None

Consistent multidict methods (#1089)Tom Christiebefore adoption2ba9c1e

line 22why, one step back
22 assert q.get_list("a") == ["123", "456"]

Use get_list consistently (#1119)Tom Christiebefore adoptione5f8743

lines 23–26why, one step back
23
24 with pytest.warns(DeprecationWarning):25 assert q.getlist("a") == ["123", "456"]26

Update link to timeout fine tuning in quickstart (#696)David Larletbefore adoption22663bc

lines 27–50why, one step back
27 assert list(q.keys()) == ["a", "b"]
28 assert list(q.values()) == ["456", "789"]29 assert list(q.items()) == [("a", "456"), ("b", "789")]30 assert len(q) == 231 assert list(q) == ["a", "b"]32 assert dict(q) == {"a": "456", "b": "789"}33 assert str(q) == "a=123&a=456&b=789"34 assert repr(q) == "QueryParams('a=123&a=456&b=789')"35 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(36 [("a", "123"), ("b", "456")]37 )38 assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")39 assert QueryParams({"a": "123", "b": "456"}) == QueryParams(40 {"b": "456", "a": "123"}41 )42 assert QueryParams() == QueryParams({})43 assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")44 assert QueryParams({"a": "123", "b": "456"}) != "invalid"4546 q = QueryParams([("a", "123"), ("a", "456")])47 assert QueryParams(q) == q484950def test_queryparam_types():

Support QueryParams(None) (#1060)Tom Christiebefore adoptionff93a01

lines 51–53why, one step back
51 q = QueryParams(None)
52 assert str(q) == ""53

Update link to timeout fine tuning in quickstart (#696)David Larletbefore adoption22663bc

lines 54–91why, one step back
54 q = QueryParams({"a": True})
55 assert str(q) == "a=true"5657 q = QueryParams({"a": False})58 assert str(q) == "a=false"5960 q = QueryParams({"a": ""})61 assert str(q) == "a="6263 q = QueryParams({"a": None})64 assert str(q) == "a="6566 q = QueryParams({"a": 1.23})67 assert str(q) == "a=1.23"6869 q = QueryParams({"a": 123})70 assert str(q) == "a=123"7172 q = QueryParams({"a": [1, 2]})73 assert str(q) == "a=1&a=2"747576def test_queryparam_setters():77 q = QueryParams({"a": 1})78 q.update([])7980 assert str(q) == "a=1"8182 q = QueryParams([("a", 1), ("a", 2)])83 q["a"] = "3"84 assert str(q) == "a=3"8586 q = QueryParams([("a", 1), ("b", 1)])87 u = QueryParams([("b", 2), ("b", 3)])88 q.update(u)8990 assert str(q) == "a=1&b=2&b=3"91 assert q["b"] == u["b"]