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 fileTake it
Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 1–2why, one step back1import json2Drop sync (#544)Tom Christiebefore adoption206c537
lines 3–4why, one step back3import pytest4Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
lines 5–7why, one step back5from httpx import URL, Client, QueryParams, Request, Response6from httpx.config import CertTypes, TimeoutTypes, VerifyTypes7from httpx.dispatch.base import DispatcherAdding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 8–9why, one step back89Drop sync (#544)Tom Christiebefore adoption206c537
line 10why, one step back10class MockDispatch(Dispatcher):Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 11–12why, one step back11 async def send(12 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 13why, one step back13 request: Request,Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 14–16why, one step back14 verify: VerifyTypes = None,15 cert: CertTypes = None,16 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 17why, one step back17 ) -> Response:Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 18–19why, one step back18 if request.url.path.startswith("/echo_queryparams"):19 body = json.dumps({"ok": "ok"}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 20why, one step back20 return Response(200, content=body, request=request)Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 21–33why, one step back212223def 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"33Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
lines 34–38why, one step back34 client = Client()35 client.params = "a=b"36 assert isinstance(client.params, QueryParams)37 assert client.params["a"] == "b"38Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
line 39why, one step back39Drop sync (#544)Tom Christiebefore adoption206c537
lines 40–41why, one step back40@pytest.mark.asyncio41async def test_client_queryparams_echo():Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 42–44why, one step back42 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 back45 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 back4748 assert response.status_code == 20049 assert response.url == URL(50 "http://example.org/echo_queryparams?first=str&second=dict"51 )