Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

59 lines · 1.5 KiB · Python

Last changed by

Drop sync (#544)Tom Christiebefore adoption206c537

History of this file

Take it

1import json23import pytest45from httpx import (6    CertTypes,7    Client,8    Dispatcher,9    QueryParams,10    Request,11    Response,12    TimeoutTypes,13    VerifyTypes,14)15from httpx.models import URL161718class MockDispatch(Dispatcher):19    async def send(20        self,21        request: Request,22        verify: VerifyTypes = None,23        cert: CertTypes = None,24        timeout: TimeoutTypes = None,25    ) -> Response:26        if request.url.path.startswith("/echo_queryparams"):27            body = json.dumps({"ok": "ok"}).encode()28            return Response(200, content=body, request=request)293031def test_client_queryparams():32    client = Client(params={"a": "b"})33    assert isinstance(client.params, QueryParams)34    assert client.params["a"] == "b"353637def test_client_queryparams_string():38    client = Client(params="a=b")39    assert isinstance(client.params, QueryParams)40    assert client.params["a"] == "b"4142    client = Client()43    client.params = "a=b"44    assert isinstance(client.params, QueryParams)45    assert client.params["a"] == "b"464748@pytest.mark.asyncio49async def test_client_queryparams_echo():50    url = "http://example.org/echo_queryparams"51    client_queryparams = "first=str"52    request_queryparams = {"second": "dict"}53    client = Client(dispatch=MockDispatch(), params=client_queryparams)54    response = await client.get(url, params=request_queryparams)5556    assert response.status_code == 20057    assert response.url == URL(58        "http://example.org/echo_queryparams?first=str&second=dict"59    )