test_async_client.py
This file
Path
tests/client/test_async_client.py
157 lines · 4.9 KiB · Python
Last changed by
Drop deprecated API (#1057)Tom Christiebefore adoption3f96e74
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)1920Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 21why, one step back21@pytest.mark.usefixtures("async_environment")Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 22–28why, one step back22async def test_get_invalid_url(server):23 async with httpx.AsyncClient() as client:24 with pytest.raises(httpx.InvalidURL):25 await client.get("invalid://example.org")262728@pytest.mark.usefixtures("async_environment")Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 29why, one step back29async def test_build_request(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 30–31why, one step back30 url = server.url.copy_with(path="/echo_headers")31 headers = {"Custom-header": "value"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 32why, one step back32 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 33–42why, one step back33 request = client.build_request("GET", url)34 request.headers.update(headers)35 response = await client.send(request)3637 assert response.status_code == 20038 assert response.url == url3940 assert response.json()["Custom-header"] == "value"4142Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 43–44why, one step back43@pytest.mark.usefixtures("async_environment")44async def test_post(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 45why, one step back45 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 46why, one step back46 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 47–50why, one step back47 response = await client.post(url, data=b"Hello, world!")48 assert response.status_code == 2004950Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 51–52why, one step back51@pytest.mark.usefixtures("async_environment")52async def test_post_json(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, json={"text": "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_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 61why, one step back61 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
line 62why, one step back62 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 63why, one step back63 body = await response.aread()Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 64–69why, one step back6465 assert response.status_code == 20066 assert body == b"Hello, world!"67 assert response.content == b"Hello, world!"6869Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 70–71why, one step back70@pytest.mark.usefixtures("async_environment")71async def test_access_content_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 72why, one step back72 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 73–80why, one step back73 async with client.stream("GET", server.url) as response:74 pass7576 assert response.status_code == 20077 with pytest.raises(httpx.ResponseNotRead):78 response.content7980Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 81–82why, one step back81@pytest.mark.usefixtures("async_environment")82async def test_stream_request(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 83–86why, one step back83 async def hello_world():84 yield b"Hello, "85 yield b"world!"86Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 87why, one step back87 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 88–91why, one step back88 response = await client.request("POST", server.url, data=hello_world())89 assert response.status_code == 2009091Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 92–93why, one step back92@pytest.mark.usefixtures("async_environment")93async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 94why, one step back94 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 95–104why, one step back95 for status_code in (200, 400, 404, 500, 505):96 response = await client.request(97 "GET", server.url.copy_with(path=f"/status/{status_code}")98 )99100 if 400 <= status_code < 600:101 with pytest.raises(httpx.HTTPError) as exc_info:102 response.raise_for_status()103 assert exc_info.value.response == response104 else:Fixed mypy errors in test_async_client.py and test_client.py (#985)Hasan Ramezanibefore adoption21d7e16
line 105why, one step back105 assert response.raise_for_status() is None # type: ignoreDrop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 106–107why, one step back106107Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 108–109why, one step back108@pytest.mark.usefixtures("async_environment")109async def test_options(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 110why, one step back110 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 111–115why, one step back111 response = await client.options(server.url)112 assert response.status_code == 200113 assert response.text == "Hello, world!"114115Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 116–117why, one step back116@pytest.mark.usefixtures("async_environment")117async def test_head(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.head(server.url)120 assert response.status_code == 200121 assert response.text == ""122123Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 124–125why, one step back124@pytest.mark.usefixtures("async_environment")125async def test_put(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–130why, one step back127 response = await client.put(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_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 133why, one step back133 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 134–137why, one step back134 response = await client.patch(server.url, data=b"Hello, world!")135 assert response.status_code == 200136137Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 138–139why, one step back138@pytest.mark.usefixtures("async_environment")139async def test_delete(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 140why, one step back140 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 141–145why, one step back141 response = await client.delete(server.url)142 assert response.status_code == 200143 assert response.text == "Hello, world!"144145Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 146–147why, one step back146@pytest.mark.usefixtures("async_environment")147async def test_100_continue(server):Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 148–150why, one step back148 headers = {"Expect": "100-continue"}149 data = b"Echo request body"150Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 151why, one step back151 async with httpx.AsyncClient() as client:Drop unused methods from BaseEvent (#626)Tom Christiebefore adoption869714f
lines 152–157why, one step back152 response = await client.post(153 server.url.copy_with(path="/echo_body"), headers=headers, data=data154 )155156 assert response.status_code == 200157 assert response.content == data