test_async_client.py
This file
Path
tests/client/test_async_client.py
184 lines · 5.7 KiB · Python
Last changed by
Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
History of this fileTake it
The walk stopped after 200 commits: lines older than bc54dd0 point at it.
Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 1–2why, one step back1from datetime import timedelta2Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
line 3why, one step back3import httpcoreBackend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 4–6why, one step back4import pytest56import httpxIncreased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
line 7why, one step back7from httpx import ASGIDispatchBackend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 8–9why, one step back89Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 10–11why, one step back10@pytest.mark.usefixtures("async_environment")11async def test_get(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 12why, one step back12 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 13why, one step back13 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 14–22why, one step back14 response = await client.get(url)15 assert response.status_code == 20016 assert response.text == "Hello, world!"17 assert response.http_version == "HTTP/1.1"18 assert response.headers19 assert repr(response) == "<Response [200 OK]>"20 assert response.elapsed > timedelta(seconds=0)2122Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 23why, one step back23@pytest.mark.usefixtures("async_environment")Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 24–30why, one step back24async def test_get_invalid_url(server):25 async with httpx.AsyncClient() as client:26 with pytest.raises(httpx.InvalidURL):27 await client.get("invalid://example.org")282930@pytest.mark.usefixtures("async_environment")Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 31why, one step back31async def test_build_request(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 32–33why, one step back32 url = server.url.copy_with(path="/echo_headers")33 headers = {"Custom-header": "value"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 34why, one step back34 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 35–44why, one step back35 request = client.build_request("GET", url)36 request.headers.update(headers)37 response = await client.send(request)3839 assert response.status_code == 20040 assert response.url == url4142 assert response.json()["Custom-header"] == "value"4344Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 45–46why, one step back45@pytest.mark.usefixtures("async_environment")46async def test_post(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 47why, one step back47 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 48why, one step back48 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 49–52why, one step back49 response = await client.post(url, data=b"Hello, world!")50 assert response.status_code == 2005152Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 53–54why, one step back53@pytest.mark.usefixtures("async_environment")54async def test_post_json(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 55why, one step back55 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 56why, one step back56 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 57–60why, one step back57 response = await client.post(url, json={"text": "Hello, world!"})58 assert response.status_code == 2005960Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 61–62why, one step back61@pytest.mark.usefixtures("async_environment")62async def test_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 63why, one step back63 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 64why, one step back64 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 65why, one step back65 body = await response.aread()Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 66–71why, one step back6667 assert response.status_code == 20068 assert body == b"Hello, world!"69 assert response.content == b"Hello, world!"7071Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 72–73why, one step back72@pytest.mark.usefixtures("async_environment")73async def test_access_content_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 74why, one step back74 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 75–82why, one step back75 async with client.stream("GET", server.url) as response:76 pass7778 assert response.status_code == 20079 with pytest.raises(httpx.ResponseNotRead):80 response.content8182Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 83–84why, one step back83@pytest.mark.usefixtures("async_environment")84async def test_stream_request(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 85–88why, one step back85 async def hello_world():86 yield b"Hello, "87 yield b"world!"88Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 89why, one step back89 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 90–93why, one step back90 response = await client.request("POST", server.url, data=hello_world())91 assert response.status_code == 2009293Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 94–95why, one step back94@pytest.mark.usefixtures("async_environment")95async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 96why, one step back96 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 97–106why, one step back97 for status_code in (200, 400, 404, 500, 505):98 response = await client.request(99 "GET", server.url.copy_with(path=f"/status/{status_code}")100 )101102 if 400 <= status_code < 600:103 with pytest.raises(httpx.HTTPError) as exc_info:104 response.raise_for_status()105 assert exc_info.value.response == response106 else:Fixed mypy errors in test_async_client.py and test_client.py (#985)Hasan Ramezanibefore adoption21d7e16
line 107why, one step back107 assert response.raise_for_status() is None # type: ignoreBackend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 108–109why, one step back108109Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 110–111why, one step back110@pytest.mark.usefixtures("async_environment")111async def test_options(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 112why, one step back112 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 113–117why, one step back113 response = await client.options(server.url)114 assert response.status_code == 200115 assert response.text == "Hello, world!"116117Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 118–119why, one step back118@pytest.mark.usefixtures("async_environment")119async def test_head(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 120why, one step back120 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 121–125why, one step back121 response = await client.head(server.url)122 assert response.status_code == 200123 assert response.text == ""124125Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 126–127why, one step back126@pytest.mark.usefixtures("async_environment")127async def test_put(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 128why, one step back128 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 129–132why, one step back129 response = await client.put(server.url, data=b"Hello, world!")130 assert response.status_code == 200131132Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 133–134why, one step back133@pytest.mark.usefixtures("async_environment")134async def test_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 135why, one step back135 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 136–139why, one step back136 response = await client.patch(server.url, data=b"Hello, world!")137 assert response.status_code == 200138139Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 140–141why, one step back140@pytest.mark.usefixtures("async_environment")141async def test_delete(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 142why, one step back142 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 143–147why, one step back143 response = await client.delete(server.url)144 assert response.status_code == 200145 assert response.text == "Hello, world!"146147Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 148–149why, one step back148@pytest.mark.usefixtures("async_environment")149async def test_100_continue(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 150–152why, one step back150 headers = {"Expect": "100-continue"}151 data = b"Echo request body"152Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 153why, one step back153 async with httpx.AsyncClient() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 154–159why, one step back154 response = await client.post(155 server.url.copy_with(path="/echo_body"), headers=headers, data=data156 )157158 assert response.status_code == 200159 assert response.content == dataIncreased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 160–184why, one step back160161162def test_dispatch_deprecated():163 dispatch = httpcore.AsyncHTTPTransport()164165 with pytest.warns(DeprecationWarning) as record:166 client = httpx.AsyncClient(dispatch=dispatch)167168 assert client.transport is dispatch169 assert len(record) == 1170 assert record[0].message.args[0] == (171 "The dispatch argument is deprecated since v0.13 and will be "172 "removed in a future release, please use 'transport'"173 )174175176def test_asgi_dispatch_deprecated():177 with pytest.warns(DeprecationWarning) as record:178 ASGIDispatch(None)179180 assert len(record) == 1181 assert (182 record[0].message.args[0]183 == "ASGIDispatch is deprecated, please use ASGITransport"184 )