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 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 pytest4Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 5–7why, one step back5from httpx import (6 CertTypes,7 Client,Drop sync (#544)Tom Christiebefore adoption206c537
line 8why, one step back8 Dispatcher,Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
line 9why, one step back9 QueryParams,Drop sync (#544)Tom Christiebefore adoption206c537
lines 10–11why, one step back10 Request,11 Response,Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 12–17why, one step back12 TimeoutTypes,13 VerifyTypes,14)15from httpx.models import URL1617Drop sync (#544)Tom Christiebefore adoption206c537
line 18why, one step back18class MockDispatch(Dispatcher):Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 19–20why, one step back19 async def send(20 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 21why, one step back21 request: Request,Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 22–24why, one step back22 verify: VerifyTypes = None,23 cert: CertTypes = None,24 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 25why, one step back25 ) -> Response:Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 26–27why, one step back26 if request.url.path.startswith("/echo_queryparams"):27 body = json.dumps({"ok": "ok"}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 28why, one step back28 return Response(200, content=body, request=request)Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 29–41why, one step back293031def 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"41Get test suite back to ~100% line coverage (#406)Seth Michael Larsonbefore adoption05f5dc2
lines 42–46why, one step back42 client = Client()43 client.params = "a=b"44 assert isinstance(client.params, QueryParams)45 assert client.params["a"] == "b"46Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
line 47why, one step back47Drop sync (#544)Tom Christiebefore adoption206c537
lines 48–49why, one step back48@pytest.mark.asyncio49async def test_client_queryparams_echo():Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 50–52why, one step back50 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 back53 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 back5556 assert response.status_code == 20057 assert response.url == URL(58 "http://example.org/echo_queryparams?first=str&second=dict"59 )