Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

54 lines · 1.6 KiB · Python

Last changed by

Httpcore interface (#804)Tom Christiebefore adoption3046e92

History of this file

Take it

The walk stopped after 200 commits: lines older than 7d45db0 point at it.

Httpcore interface (#804)Tom Christiebefore adoption3046e92

line 1why, one step back
1import typing

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

line 2why, one step back
2

Httpcore interface (#804)Tom Christiebefore adoption3046e92

line 3why, one step back
3import httpcore

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 4–5why, one step back
4import pytest
5

Httpcore interface (#804)Tom Christiebefore adoption3046e92

lines 6–7why, one step back
6from httpx import URL, AsyncClient, Headers, QueryParams
7from httpx._content_streams import ContentStream, JSONStream

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 8–9why, one step back
8
9

Httpcore interface (#804)Tom Christiebefore adoption3046e92

lines 10–11why, one step back
10class MockDispatch(httpcore.AsyncHTTPTransport):
11 async def request(

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

line 12why, one step back
12 self,

Httpcore interface (#804)Tom Christiebefore adoption3046e92

lines 13–23why, one step back
13 method: bytes,
14 url: typing.Tuple[bytes, bytes, int, bytes],15 headers: typing.List[typing.Tuple[bytes, bytes]],16 stream: ContentStream,17 timeout: typing.Dict[str, typing.Optional[float]] = None,18 ) -> typing.Tuple[19 bytes, int, bytes, typing.List[typing.Tuple[bytes, bytes]], ContentStream20 ]:21 headers = Headers()22 body = JSONStream({"ok": "ok"})23 return b"HTTP/1.1", 200, b"OK", headers, body

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 24–26why, one step back
24
2526def test_client_queryparams():

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 27why, one step back
27 client = AsyncClient(params={"a": "b"})

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 28–32why, one step back
28 assert isinstance(client.params, QueryParams)
29 assert client.params["a"] == "b"303132def test_client_queryparams_string():

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 33why, one step back
33 client = AsyncClient(params="a=b")

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 34–36why, one step back
34 assert isinstance(client.params, QueryParams)
35 assert client.params["a"] == "b"36

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 37why, one step back
37 client = AsyncClient()

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 38–47why, one step back
38 client.params = "a=b"
39 assert isinstance(client.params, QueryParams)40 assert client.params["a"] == "b"414243@pytest.mark.asyncio44async def test_client_queryparams_echo():45 url = "http://example.org/echo_queryparams"46 client_queryparams = "first=str"47 request_queryparams = {"second": "dict"}

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 48why, one step back
48 client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)

Link to ASGI docs (#577)Tom Christiebefore adoption7d45db0

lines 49–54why, one step back
49 response = await client.get(url, params=request_queryparams)
5051 assert response.status_code == 20052 assert response.url == URL(53 "http://example.org/echo_queryparams?first=str&second=dict"54 )