Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

54 lines · 1.6 KiB · Python

Last changed by

Httpcore interface (#804)Tom Christiebefore adoption3046e92

History of this file

Take it

1import typing23import httpcore4import pytest56from httpx import URL, AsyncClient, Headers, QueryParams7from httpx._content_streams import ContentStream, JSONStream8910class MockDispatch(httpcore.AsyncHTTPTransport):11    async def request(12        self,13        method: bytes,14        url: typing.Tuple[bytes, bytes, int, bytes],15        headers: typing.List[typing.Tuple[bytes, bytes]],16        stream: ContentStream,17        timeout: typing.Dict[str, typing.Optional[float]] = None,18    ) -> typing.Tuple[19        bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream20    ]:21        headers = Headers()22        body = JSONStream({"ok": "ok"})23        return b"HTTP/1.1", 200, b"OK", headers, body242526def test_client_queryparams():27    client = AsyncClient(params={"a": "b"})28    assert isinstance(client.params, QueryParams)29    assert client.params["a"] == "b"303132def test_client_queryparams_string():33    client = AsyncClient(params="a=b")34    assert isinstance(client.params, QueryParams)35    assert client.params["a"] == "b"3637    client = AsyncClient()38    client.params = "a=b"39    assert isinstance(client.params, QueryParams)40    assert client.params["a"] == "b"414243@pytest.mark.asyncio44async def test_client_queryparams_echo():45    url = "http://example.org/echo_queryparams"46    client_queryparams = "first=str"47    request_queryparams = {"second": "dict"}48    client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)49    response = await client.get(url, params=request_queryparams)5051    assert response.status_code == 20052    assert response.url == URL(53        "http://example.org/echo_queryparams?first=str&second=dict"54    )