test_async_client.py
This file
Path
tests/client/test_async_client.py
150 lines · 4.7 KiB · Python
Last changed by
Httpcore interface (#804)Tom Christiebefore adoption3046e92
History of this fileTake it
The walk stopped after 200 commits: lines older than 5aca0c0 point at it.
Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
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):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
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:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
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)1920Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 21–22why, one step back21@pytest.mark.usefixtures("async_environment")22async def test_build_request(server):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 23–24why, one step back23 url = server.url.copy_with(path="/echo_headers")24 headers = {"Custom-header": "value"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 25why, one step back25 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 26–35why, one step back26 request = client.build_request("GET", url)27 request.headers.update(headers)28 response = await client.send(request)2930 assert response.status_code == 20031 assert response.url == url3233 assert response.json()["Custom-header"] == "value"3435Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 36–37why, one step back36@pytest.mark.usefixtures("async_environment")37async def test_post(server):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
line 38why, one step back38 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 39why, one step back39 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 40–43why, one step back40 response = await client.post(url, data=b"Hello, world!")41 assert response.status_code == 2004243Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 44–45why, one step back44@pytest.mark.usefixtures("async_environment")45async def test_post_json(server):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
line 46why, one step back46 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 47why, one step back47 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 48–51why, one step back48 response = await client.post(url, json={"text": "Hello, world!"})49 assert response.status_code == 2005051Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 52–53why, one step back52@pytest.mark.usefixtures("async_environment")53async def test_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 54why, one step back54 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 55why, one step back55 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 56why, one step back56 body = await response.aread()Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 57why, one step back57Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 58–62why, one step back58 assert response.status_code == 20059 assert body == b"Hello, world!"60 assert response.content == b"Hello, world!"6162Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 63–64why, one step back63@pytest.mark.usefixtures("async_environment")64async def test_access_content_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 65why, one step back65 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 66–68why, one step back66 async with client.stream("GET", server.url) as response:67 pass68Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 69–73why, one step back69 assert response.status_code == 20070 with pytest.raises(httpx.ResponseNotRead):71 response.content7273Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 74–75why, one step back74@pytest.mark.usefixtures("async_environment")75async def test_stream_request(server):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 76–79why, one step back76 async def hello_world():77 yield b"Hello, "78 yield b"world!"79Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 80why, one step back80 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 81–84why, one step back81 response = await client.request("POST", server.url, data=hello_world())82 assert response.status_code == 2008384Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 85–86why, one step back85@pytest.mark.usefixtures("async_environment")86async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 87why, one step back87 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 88–100why, one step back88 for status_code in (200, 400, 404, 500, 505):89 response = await client.request(90 "GET", server.url.copy_with(path=f"/status/{status_code}")91 )9293 if 400 <= status_code < 600:94 with pytest.raises(httpx.HTTPError) as exc_info:95 response.raise_for_status()96 assert exc_info.value.response == response97 else:98 assert response.raise_for_status() is None99100Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 101–102why, one step back101@pytest.mark.usefixtures("async_environment")102async def test_options(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 103why, one step back103 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 104–108why, one step back104 response = await client.options(server.url)105 assert response.status_code == 200106 assert response.text == "Hello, world!"107108Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 109–110why, one step back109@pytest.mark.usefixtures("async_environment")110async def test_head(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 111why, one step back111 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 112–116why, one step back112 response = await client.head(server.url)113 assert response.status_code == 200114 assert response.text == ""115116Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 117–118why, one step back117@pytest.mark.usefixtures("async_environment")118async def test_put(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 119why, one step back119 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 120–123why, one step back120 response = await client.put(server.url, data=b"Hello, world!")121 assert response.status_code == 200122123Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 124–125why, one step back124@pytest.mark.usefixtures("async_environment")125async def test_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 126why, one step back126 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 127–130why, one step back127 response = await client.patch(server.url, data=b"Hello, world!")128 assert response.status_code == 200129130Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 131–132why, one step back131@pytest.mark.usefixtures("async_environment")132async def test_delete(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 133why, one step back133 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 134–138why, one step back134 response = await client.delete(server.url)135 assert response.status_code == 200136 assert response.text == "Hello, world!"137138Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 139–140why, one step back139@pytest.mark.usefixtures("async_environment")140async def test_100_continue(server):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 141–143why, one step back141 headers = {"Expect": "100-continue"}142 data = b"Echo request body"143Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 144why, one step back144 async with httpx.AsyncClient() as client:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 145–150why, one step back145 response = await client.post(146 server.url.copy_with(path="/echo_body"), headers=headers, data=data147 )148149 assert response.status_code == 200150 assert response.content == data