Skip to content
Myr

test_queryparams.py

This file

Path

tests/client/test_queryparams.py

51 lines · 1.5 KiB · Python

Last changed by

Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b

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

Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b

lines 5–7why, one step back
5from httpx import URL, Client, QueryParams, Request, Response
6from httpx.config import CertTypes, TimeoutTypes, VerifyTypes7from httpx.dispatch.base import Dispatcher

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 8–9why, one step back
8
9

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 11–12why, one step back
11 async def send(
12 self,

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 14–16why, one step back
14 verify: VerifyTypes = None,
15 cert: CertTypes = None,16 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

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

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 21–33why, one step back
21
2223def test_client_queryparams():24 client = Client(params={"a": "b"})25 assert isinstance(client.params, QueryParams)26 assert client.params["a"] == "b"272829def test_client_queryparams_string():30 client = Client(params="a=b")31 assert isinstance(client.params, QueryParams)32 assert client.params["a"] == "b"33

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

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

line 39why, one step back
39

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

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

Drop sync (#544)Tom Christiebefore adoption206c537

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

Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f

lines 47–51why, one step back
47
48 assert response.status_code == 20049 assert response.url == URL(50 "http://example.org/echo_queryparams?first=str&second=dict"51 )