test_queryparams.py
This file
Path
tests/client/test_queryparams.py
51 lines · 1.6 KiB · Python
Last changed by
Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
History of this fileTake it
1import typing23import httpcore45import httpx6from httpx._content_streams import ContentStream, JSONStream789class MockTransport(httpcore.SyncHTTPTransport):10 def request(11 self,12 method: bytes,13 url: typing.Tuple[bytes, bytes, typing.Optional[int], bytes],14 headers: typing.List[typing.Tuple[bytes, bytes]] = None,15 stream: httpcore.SyncByteStream = None,16 timeout: typing.Mapping[str, typing.Optional[float]] = None,17 ) -> typing.Tuple[18 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream19 ]:20 body = JSONStream({"ok": "ok"})21 return b"HTTP/1.1", 200, b"OK", [], body222324def test_client_queryparams():25 client = httpx.Client(params={"a": "b"})26 assert isinstance(client.params, httpx.QueryParams)27 assert client.params["a"] == "b"282930def test_client_queryparams_string():31 client = httpx.Client(params="a=b")32 assert isinstance(client.params, httpx.QueryParams)33 assert client.params["a"] == "b"3435 client = httpx.Client()36 client.params = "a=b" # type: ignore37 assert isinstance(client.params, httpx.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 client = httpx.Client(transport=MockTransport(), params=client_queryparams)46 response = client.get(url, params=request_queryparams)4748 assert response.status_code == 20049 assert response.url == httpx.URL(50 "http://example.org/echo_queryparams?first=str&second=dict"51 )