test_queryparams.py
This file
Path
tests/models/test_queryparams.py
125 lines · 3.3 KiB · Python
Last changed by
Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2
History of this fileTake it
The walk stopped after 200 commits: lines older than 78cf16a point at it.
Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 1–2why, one step back1import pytest2Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 3why, one step back3import httpxDrop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 4–11why, one step back456@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},Allow tuple as input of query parameters. (#1426)SarunasAznabefore adoption8696405
lines 12–13why, one step back12 [("a", "123"), ("a", "456"), ("b", "789")],13 (("a", "123"), ("a", "456"), ("b", "789")),Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 14–16why, one step back14 ],15)16def test_queryparams(source):Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 17why, one step back17 q = httpx.QueryParams(source)Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 18–20why, one step back18 assert "a" in q19 assert "A" not in q20 assert "c" not in qTweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5
lines 21–22why, one step back21 assert q["a"] == "123"22 assert q.get("a") == "123"Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 23–26why, one step back23 assert q.get("nope", default=None) is None24 assert q.get_list("a") == ["123", "456"]2526 assert list(q.keys()) == ["a", "b"]Tweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5
lines 27–28why, one step back27 assert list(q.values()) == ["123", "789"]28 assert list(q.items()) == [("a", "123"), ("b", "789")]Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 29–30why, one step back29 assert len(q) == 230 assert list(q) == ["a", "b"]Tweak QueryParams implementation (#1598)Tom Christiebefore adoption8fe32c5
line 31why, one step back31 assert dict(q) == {"a": "123", "b": "789"}Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 32–33why, one step back32 assert str(q) == "a=123&a=456&b=789"33 assert repr(q) == "QueryParams('a=123&a=456&b=789')"Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 34why, one step back34 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 35–36why, one step back35 [("a", "123"), ("b", "456")]36 )Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 37–40why, one step back37 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(38 "a=123&b=456"39 )40 assert httpx.QueryParams({"a": "123", "b": "456"}) == httpx.QueryParams(Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 41–42why, one step back41 {"b": "456", "a": "123"}42 )Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 43–47why, one step back43 assert httpx.QueryParams() == httpx.QueryParams({})44 assert httpx.QueryParams([("a", "123"), ("a", "456")]) == httpx.QueryParams(45 "a=123&a=456"46 )47 assert httpx.QueryParams({"a": "123", "b": "456"}) != "invalid"Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
line 48why, one step back48Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 49–50why, one step back49 q = httpx.QueryParams([("a", "123"), ("a", "456")])50 assert httpx.QueryParams(q) == qDrop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 51–53why, one step back515253def test_queryparam_types():Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 54why, one step back54 q = httpx.QueryParams(None)Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 55–56why, one step back55 assert str(q) == ""56Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 57why, one step back57 q = httpx.QueryParams({"a": True})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 58–59why, one step back58 assert str(q) == "a=true"59Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 60why, one step back60 q = httpx.QueryParams({"a": False})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 61–62why, one step back61 assert str(q) == "a=false"62Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 63why, one step back63 q = httpx.QueryParams({"a": ""})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 64–65why, one step back64 assert str(q) == "a="65Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 66why, one step back66 q = httpx.QueryParams({"a": None})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 67–68why, one step back67 assert str(q) == "a="68Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 69why, one step back69 q = httpx.QueryParams({"a": 1.23})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 70–71why, one step back70 assert str(q) == "a=1.23"71Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 72why, one step back72 q = httpx.QueryParams({"a": 123})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 73–74why, one step back73 assert str(q) == "a=123"74Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 75why, one step back75 q = httpx.QueryParams({"a": [1, 2]})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 76–78why, one step back76 assert str(q) == "a=1&a=2"7778Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2
lines 79–82why, one step back79def test_queryparam_update_is_hard_deprecated():80 q = httpx.QueryParams("a=123")81 with pytest.raises(RuntimeError):82 q.update({"a": "456"})Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 83–84why, one step back8384Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2
lines 85–88why, one step back85def test_queryparam_setter_is_hard_deprecated():86 q = httpx.QueryParams("a=123")87 with pytest.raises(RuntimeError):88 q["a"] = "456"Drop HSTS Preloading (#1110)Florimond Mancabefore adoption78cf16a
lines 89–90why, one step back8990Immutable QueryParams (#1600)Tom Christiebefore adoption2abb2f2
lines 91–125why, one step back91def test_queryparam_set():92 q = httpx.QueryParams("a=123")93 q = q.set("a", "456")94 assert q == httpx.QueryParams("a=456")959697def test_queryparam_add():98 q = httpx.QueryParams("a=123")99 q = q.add("a", "456")100 assert q == httpx.QueryParams("a=123&a=456")101102103def test_queryparam_remove():104 q = httpx.QueryParams("a=123")105 q = q.remove("a")106 assert q == httpx.QueryParams("")107108109def test_queryparam_merge():110 q = httpx.QueryParams("a=123")111 q = q.merge({"b": "456"})112 assert q == httpx.QueryParams("a=123&b=456")113 q = q.merge({"a": "000", "c": "789"})114 assert q == httpx.QueryParams("a=000&b=456&c=789")115116117def test_queryparams_are_hashable():118 params = (119 httpx.QueryParams("a=123"),120 httpx.QueryParams({"a": 123}),121 httpx.QueryParams("b=456"),122 httpx.QueryParams({"b": 456}),123 )124125 assert len(set(params)) == 2