MCPcopy Create free account
hub / github.com/encode/starlette / test_queryparams

Function test_queryparams

tests/test_datastructures.py:396–421  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

394
395
396def test_queryparams() -> None:
397 q = QueryParams("a=123&a=456&b=789")
398 assert "a" in q
399 assert "A" not in q
400 assert "c" not in q
401 assert q["a"] == "456"
402 assert q.get("a") == "456"
403 assert q.get("nope", None) is None
404 assert q.getlist("a") == ["123", "456"]
405 assert list(q.keys()) == ["a", "b"]
406 assert list(q.values()) == ["456", "789"]
407 assert list(q.items()) == [("a", "456"), ("b", "789")]
408 assert len(q) == 2
409 assert list(q) == ["a", "b"]
410 assert dict(q) == {"a": "456", "b": "789"}
411 assert str(q) == "a=123&a=456&b=789"
412 assert repr(q) == "QueryParams('a=123&a=456&b=789')"
413 assert QueryParams({"a": "123", "b": "456"}) == QueryParams([("a", "123"), ("b", "456")])
414 assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")
415 assert QueryParams({"a": "123", "b": "456"}) == QueryParams({"b": "456", "a": "123"})
416 assert QueryParams() == QueryParams({})
417 assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")
418 assert QueryParams({"a": "123", "b": "456"}) != "invalid"
419
420 q = QueryParams([("a", "123"), ("a", "456")])
421 assert QueryParams(q) == q
422
423
424@pytest.mark.anyio

Callers

nothing calls this directly

Calls 6

QueryParamsClass · 0.90
getMethod · 0.45
getlistMethod · 0.45
keysMethod · 0.45
valuesMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected