Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

36 lines · 1.1 KiB · Python

Last changed by

Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d

History of this file

Take it

1import httpx2from tests.utils import MockTransport345def hello_world(request: httpx.Request) -> httpx.Response:6    return httpx.Response(200, content=b"Hello, world")789def test_client_queryparams():10    client = httpx.Client(params={"a": "b"})11    assert isinstance(client.params, httpx.QueryParams)12    assert client.params["a"] == "b"131415def test_client_queryparams_string():16    client = httpx.Client(params="a=b")17    assert isinstance(client.params, httpx.QueryParams)18    assert client.params["a"] == "b"1920    client = httpx.Client()21    client.params = "a=b"  # type: ignore22    assert isinstance(client.params, httpx.QueryParams)23    assert client.params["a"] == "b"242526def test_client_queryparams_echo():27    url = "http://example.org/echo_queryparams"28    client_queryparams = "first=str"29    request_queryparams = {"second": "dict"}30    client = httpx.Client(31        transport=MockTransport(hello_world), params=client_queryparams32    )33    response = client.get(url, params=request_queryparams)3435    assert response.status_code == 20036    assert response.url == "http://example.org/echo_queryparams?first=str&second=dict"