test_async_client.py
This file
Path
tests/client/test_async_client.py
165 lines · 5.1 KiB · Python
Last changed by
Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
History of this fileTake it
The walk stopped after 200 commits: lines older than 869714f point at it.
Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 1–7why, one step back1from datetime import timedelta23import pytest45import httpx67Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 8–9why, one step back8@pytest.mark.usefixtures("async_environment")9async def test_get(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 10why, one step back10 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 11why, one step back11 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 12–20why, one step back12 response = await client.get(url)13 assert response.status_code == 20014 assert response.text == "Hello, world!"15 assert response.http_version == "HTTP/1.1"16 assert response.headers17 assert repr(response) == "<Response [200 OK]>"18 assert response.elapsed > timedelta(seconds=0)1920Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
lines 21–28why, one step back21@pytest.mark.parametrize(22 "url",23 [24 pytest.param("invalid://example.org", id="scheme-not-http(s)"),25 pytest.param("://example.org", id="no-scheme"),26 pytest.param("http://", id="no-host"),27 ],28)Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 29why, one step back29@pytest.mark.usefixtures("async_environment")Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
line 30why, one step back30async def test_get_invalid_url(server, url):Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 31–32why, one step back31 async with httpx.AsyncClient() as client:32 with pytest.raises(httpx.InvalidURL):Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
line 33why, one step back33 await client.get(url)Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 34–36why, one step back343536@pytest.mark.usefixtures("async_environment")Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 37why, one step back37async def test_build_request(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 38–39why, one step back38 url = server.url.copy_with(path="/echo_headers")39 headers = {"Custom-header": "value"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 40why, one step back40 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 41–50why, one step back41 request = client.build_request("GET", url)42 request.headers.update(headers)43 response = await client.send(request)4445 assert response.status_code == 20046 assert response.url == url4748 assert response.json()["Custom-header"] == "value"4950Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 51–52why, one step back51@pytest.mark.usefixtures("async_environment")52async def test_post(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 53why, one step back53 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 54why, one step back54 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 55–58why, one step back55 response = await client.post(url, data=b"Hello, world!")56 assert response.status_code == 2005758Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 59–60why, one step back59@pytest.mark.usefixtures("async_environment")60async def test_post_json(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 61why, one step back61 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 62why, one step back62 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 63–66why, one step back63 response = await client.post(url, json={"text": "Hello, world!"})64 assert response.status_code == 2006566Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 67–68why, one step back67@pytest.mark.usefixtures("async_environment")68async def test_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 69why, one step back69 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 70why, one step back70 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 71why, one step back71 body = await response.aread()Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 72–77why, one step back7273 assert response.status_code == 20074 assert body == b"Hello, world!"75 assert response.content == b"Hello, world!"7677Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 78–79why, one step back78@pytest.mark.usefixtures("async_environment")79async def test_access_content_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 80why, one step back80 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 81–88why, one step back81 async with client.stream("GET", server.url) as response:82 pass8384 assert response.status_code == 20085 with pytest.raises(httpx.ResponseNotRead):86 response.content8788Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 89–90why, one step back89@pytest.mark.usefixtures("async_environment")90async def test_stream_request(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 91–94why, one step back91 async def hello_world():92 yield b"Hello, "93 yield b"world!"94Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 95why, one step back95 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 96–99why, one step back96 response = await client.request("POST", server.url, data=hello_world())97 assert response.status_code == 2009899Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 100–101why, one step back100@pytest.mark.usefixtures("async_environment")101async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 102why, one step back102 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 103–108why, one step back103 for status_code in (200, 400, 404, 500, 505):104 response = await client.request(105 "GET", server.url.copy_with(path=f"/status/{status_code}")106 )107108 if 400 <= status_code < 600:Raise HTTPStatusError in raise_from_status (#1072)François Voronbefore adoption27b0dbc
line 109why, one step back109 with pytest.raises(httpx.HTTPStatusError) as exc_info:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 110–112why, one step back110 response.raise_for_status()111 assert exc_info.value.response == response112 else:Fixed mypy errors in test_async_client.py and test_client.py (#985)Hasan Ramezanibefore adoption21d7e16
line 113why, one step back113 assert response.raise_for_status() is None # type: ignoreDrop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 114–115why, one step back114115Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 116–117why, one step back116@pytest.mark.usefixtures("async_environment")117async def test_options(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 118why, one step back118 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 119–123why, one step back119 response = await client.options(server.url)120 assert response.status_code == 200121 assert response.text == "Hello, world!"122123Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 124–125why, one step back124@pytest.mark.usefixtures("async_environment")125async def test_head(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 126why, one step back126 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 127–131why, one step back127 response = await client.head(server.url)128 assert response.status_code == 200129 assert response.text == ""130131Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 132–133why, one step back132@pytest.mark.usefixtures("async_environment")133async def test_put(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 134why, one step back134 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 135–138why, one step back135 response = await client.put(server.url, data=b"Hello, world!")136 assert response.status_code == 200137138Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 139–140why, one step back139@pytest.mark.usefixtures("async_environment")140async def test_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 141why, one step back141 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 142–145why, one step back142 response = await client.patch(server.url, data=b"Hello, world!")143 assert response.status_code == 200144145Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 146–147why, one step back146@pytest.mark.usefixtures("async_environment")147async def test_delete(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 148why, one step back148 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 149–153why, one step back149 response = await client.delete(server.url)150 assert response.status_code == 200151 assert response.text == "Hello, world!"152153Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 154–155why, one step back154@pytest.mark.usefixtures("async_environment")155async def test_100_continue(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 156–158why, one step back156 headers = {"Expect": "100-continue"}157 data = b"Echo request body"158Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 159why, one step back159 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 160–165why, one step back160 response = await client.post(161 server.url.copy_with(path="/echo_body"), headers=headers, data=data162 )163164 assert response.status_code == 200165 assert response.content == data