Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

49 lines · 1.6 KiB · Python

Last changed by

Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209

History of this file

Take it

1import typing23import httpcore45import httpx6from httpx._content_streams import ContentStream, JSONStream789class MockTransport(httpcore.SyncHTTPTransport):10    def request(11        self,12        method: bytes,13        url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],14        headers: typing.List[typing.Tuple[bytes, bytes]] = None,15        stream: httpcore.SyncByteStream = None,16        timeout: typing.Mapping[str, typing.Optional[float]] = None,17    ) -> typing.Tuple[18        bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream19    ]:20        body = JSONStream({"ok": "ok"})21        return b"HTTP/1.1", 200, b"OK", [], body222324def test_client_queryparams():25    client = httpx.Client(params={"a": "b"})26    assert isinstance(client.params, httpx.QueryParams)27    assert client.params["a"] == "b"282930def test_client_queryparams_string():31    client = httpx.Client(params="a=b")32    assert isinstance(client.params, httpx.QueryParams)33    assert client.params["a"] == "b"3435    client = httpx.Client()36    client.params = "a=b"  # type: ignore37    assert isinstance(client.params, httpx.QueryParams)38    assert client.params["a"] == "b"394041def test_client_queryparams_echo():42    url = "http://example.org/echo_queryparams"43    client_queryparams = "first=str"44    request_queryparams = {"second": "dict"}45    client = httpx.Client(transport=MockTransport(), params=client_queryparams)46    response = client.get(url, params=request_queryparams)4748    assert response.status_code == 20049    assert response.url == "http://example.org/echo_queryparams?first=str&second=dict"