test_queryparams.py
This file
Path
tests/client/test_queryparams.py
53 lines · 1.7 KiB · Python
Last changed by
Update to httpcore 0.10 (#1126)Tom Christiebefore adoption876e722
History of this fileTake it
1import typing23import httpcore4import pytest56from httpx import URL, AsyncClient, QueryParams7from httpx._content_streams import ContentStream, JSONStream8910class MockTransport(httpcore.AsyncHTTPTransport):11 async def request(12 self,13 method: bytes,14 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],15 headers: typing.List[typing.Tuple[bytes, bytes]] = None,16 stream: httpcore.AsyncByteStream = None,17 timeout: typing.Mapping[str, typing.Optional[float]] = None,18 ) -> typing.Tuple[19 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream20 ]:21 body = JSONStream({"ok": "ok"})22 return b"HTTP/1.1", 200, b"OK", [], body232425def test_client_queryparams():26 client = AsyncClient(params={"a": "b"})27 assert isinstance(client.params, QueryParams)28 assert client.params["a"] == "b"293031def test_client_queryparams_string():32 client = AsyncClient(params="a=b")33 assert isinstance(client.params, QueryParams)34 assert client.params["a"] == "b"3536 client = AsyncClient()37 client.params = "a=b" # type: ignore38 assert isinstance(client.params, QueryParams)39 assert client.params["a"] == "b"404142@pytest.mark.asyncio43async def test_client_queryparams_echo():44 url = "http://example.org/echo_queryparams"45 client_queryparams = "first=str"46 request_queryparams = {"second": "dict"}47 client = AsyncClient(transport=MockTransport(), params=client_queryparams)48 response = await client.get(url, params=request_queryparams)4950 assert response.status_code == 20051 assert response.url == URL(52 "http://example.org/echo_queryparams?first=str&second=dict"53 )