Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

51 lines · 1.5 KiB · Python

Last changed by

Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b

History of this file

Take it

1import json23import pytest45from httpx import URL, AsyncClient, QueryParams, Request, Response6from httpx.config import CertTypes, TimeoutTypes, VerifyTypes7from httpx.dispatch.base import AsyncDispatcher8910class MockDispatch(AsyncDispatcher):11    async def send(12        self,13        request: Request,14        verify: VerifyTypes = None,15        cert: CertTypes = None,16        timeout: TimeoutTypes = None,17    ) -> Response:18        if request.url.path.startswith("/echo_queryparams"):19            body = json.dumps({"ok": "ok"}).encode()20            return Response(200, content=body, request=request)212223def test_client_queryparams():24    client = AsyncClient(params={"a": "b"})25    assert isinstance(client.params, QueryParams)26    assert client.params["a"] == "b"272829def test_client_queryparams_string():30    client = AsyncClient(params="a=b")31    assert isinstance(client.params, QueryParams)32    assert client.params["a"] == "b"3334    client = AsyncClient()35    client.params = "a=b"36    assert isinstance(client.params, QueryParams)37    assert client.params["a"] == "b"383940@pytest.mark.asyncio41async def test_client_queryparams_echo():42    url = "http://example.org/echo_queryparams"43    client_queryparams = "first=str"44    request_queryparams = {"second": "dict"}45    client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)46    response = await client.get(url, params=request_queryparams)4748    assert response.status_code == 20049    assert response.url == URL(50        "http://example.org/echo_queryparams?first=str&second=dict"51    )