Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

56 lines · 1.5 KiB · Python

Last changed by

Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2

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"3940    client = Client()41    client.params = "a=b"42    assert isinstance(client.params, QueryParams)43    assert client.params["a"] == "b"444546def test_client_queryparams_echo():47    url = "http://example.org/echo_queryparams"48    client_queryparams = "first=str"49    request_queryparams = {"second": "dict"}50    with Client(dispatch=MockDispatch(), params=client_queryparams) as client:51        response = client.get(url, params=request_queryparams)5253    assert response.status_code == 20054    assert response.url == URL(55        "http://example.org/echo_queryparams?first=str&second=dict"56    )