Skip to content
Myr

test_queryparams.py

This file

Path

tests/models/test_queryparams.py

33 lines · 1.2 KiB · Python

Last changed by

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

History of this file

Take it

1from httpcore import QueryParams234def test_queryparams():5    q = QueryParams("a=123&a=456&b=789")6    assert "a" in q7    assert "A" not in q8    assert "c" not in q9    assert q["a"] == "456"10    assert q.get("a") == "456"11    assert q.get("nope", default=None) is None12    assert q.getlist("a") == ["123", "456"]13    assert list(q.keys()) == ["a", "b"]14    assert list(q.values()) == ["456", "789"]15    assert list(q.items()) == [("a", "456"), ("b", "789")]16    assert len(q) == 217    assert list(q) == ["a", "b"]18    assert dict(q) == {"a": "456", "b": "789"}19    assert str(q) == "a=123&a=456&b=789"20    assert repr(q) == "QueryParams('a=123&a=456&b=789')"21    assert QueryParams({"a": "123", "b": "456"}) == QueryParams(22        [("a", "123"), ("b", "456")]23    )24    assert QueryParams({"a": "123", "b": "456"}) == QueryParams("a=123&b=456")25    assert QueryParams({"a": "123", "b": "456"}) == QueryParams(26        {"b": "456", "a": "123"}27    )28    assert QueryParams() == QueryParams({})29    assert QueryParams([("a", "123"), ("a", "456")]) == QueryParams("a=123&a=456")30    assert QueryParams({"a": "123", "b": "456"}) != "invalid"3132    q = QueryParams([("a", "123"), ("a", "456")])33    assert QueryParams(q) == q