Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

51 lines · 1.4 KiB · Python

Last changed by

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

History of this file

Take it

1import json23from httpx import (4    AsyncDispatcher,5    AsyncRequest,6    AsyncResponse,7    CertTypes,8    Client,9    QueryParams,10    TimeoutTypes,11    VerifyTypes,12)13from httpx.models import URL141516class MockDispatch(AsyncDispatcher):17    async def send(18        self,19        request: AsyncRequest,20        verify: VerifyTypes = None,21        cert: CertTypes = None,22        timeout: TimeoutTypes = None,23    ) -> AsyncResponse:24        if request.url.path.startswith("/echo_queryparams"):25            body = json.dumps({"ok": "ok"}).encode()26            return AsyncResponse(200, content=body, request=request)272829def test_client_queryparams():30    client = Client(params={"a": "b"})31    assert isinstance(client.params, QueryParams)32    assert client.params["a"] == "b"333435def test_client_queryparams_string():36    client = Client(params="a=b")37    assert isinstance(client.params, 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    with Client(dispatch=MockDispatch(), params=client_queryparams) as client:46        response = 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    )