test_queryparams.py
This file
Path
tests/client/test_queryparams.py
51 lines · 1.5 KiB · Python
Last changed by
Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
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 pytest4Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 5why, one step back5from httpx import URL, AsyncClient, QueryParams, Request, ResponseTighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
lines 6–7why, one step back6from 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–23why, one step back212223def test_client_queryparams():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 24why, one step back24 client = AsyncClient(params={"a": "b"})Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 25–29why, one step back25 assert isinstance(client.params, QueryParams)26 assert client.params["a"] == "b"272829def test_client_queryparams_string():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 30why, one step back30 client = AsyncClient(params="a=b")Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 31–33why, one step back31 assert isinstance(client.params, QueryParams)32 assert client.params["a"] == "b"33Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 34why, one step back34 client = AsyncClient()Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
lines 35–38why, one step back35 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"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 45why, one step back45 client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)Drop sync (#544)Tom Christiebefore adoption206c537
line 46why, one step back46 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 )