Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

59 lines · 1.5 KiB · Python

Last changed by

Drop sync (#544)Tom Christiebefore adoption206c537

History of this file

Take it

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 1–2why, one step back
1import json
2

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 5–7why, one step back
5from httpx import (
6 CertTypes,7 Client,

Drop sync (#544)Tom Christiebefore adoption206c537

line 8why, one step back
8 Dispatcher,

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

line 9why, one step back
9 QueryParams,

Drop sync (#544)Tom Christiebefore adoption206c537

lines 10–11why, one step back
10 Request,
11 Response,

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 12–17why, one step back
12 TimeoutTypes,
13 VerifyTypes,14)15from httpx.models import URL1617

Drop sync (#544)Tom Christiebefore adoption206c537

line 18why, one step back
18class MockDispatch(Dispatcher):

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 19–20why, one step back
19 async def send(
20 self,

Drop sync (#544)Tom Christiebefore adoption206c537

line 21why, one step back
21 request: Request,

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 22–24why, one step back
22 verify: VerifyTypes = None,
23 cert: CertTypes = None,24 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

line 25why, one step back
25 ) -> Response:

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 26–27why, one step back
26 if request.url.path.startswith("/echo_queryparams"):
27 body = json.dumps({"ok": "ok"}).encode()

Drop sync (#544)Tom Christiebefore adoption206c537

line 28why, one step back
28 return Response(200, content=body, request=request)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 29–41why, one step back
29
3031def test_client_queryparams():32 client = Client(params={"a": "b"})33 assert isinstance(client.params, QueryParams)34 assert client.params["a"] == "b"353637def test_client_queryparams_string():38 client = Client(params="a=b")39 assert isinstance(client.params, QueryParams)40 assert client.params["a"] == "b"41

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

lines 42–46why, one step back
42 client = Client()
43 client.params = "a=b"44 assert isinstance(client.params, QueryParams)45 assert client.params["a"] == "b"46

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

line 47why, one step back
47

Drop sync (#544)Tom Christiebefore adoption206c537

lines 48–49why, one step back
48@pytest.mark.asyncio
49async def test_client_queryparams_echo():

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 50–52why, one step back
50 url = "http://example.org/echo_queryparams"
51 client_queryparams = "first=str"52 request_queryparams = {"second": "dict"}

Drop sync (#544)Tom Christiebefore adoption206c537

lines 53–54why, one step back
53 client = Client(dispatch=MockDispatch(), params=client_queryparams)
54 response = await client.get(url, params=request_queryparams)

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 55–59why, one step back
55
56 assert response.status_code == 20057 assert response.url == URL(58 "http://example.org/echo_queryparams?first=str&second=dict"59 )