test_async_client.py
This file
Path
tests/client/test_async_client.py
168 lines · 5.2 KiB · Python
Last changed by
Full coverage, with exception of URLLib3Transport (#1086)Tom Christiebefore adoption2d491c9
History of this fileTake it
The walk stopped after 200 commits: lines older than e34df7a point at it.
Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
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):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
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:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 12–19why, 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)19Full coverage, with exception of URLLib3Transport (#1086)Tom Christiebefore adoption2d491c9
lines 20–22why, one step back20 with pytest.raises(httpx.NotRedirectResponse):21 await response.anext()22Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
line 23why, one step back23Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
lines 24–31why, one step back24@pytest.mark.parametrize(25 "url",26 [27 pytest.param("invalid://example.org", id="scheme-not-http(s)"),28 pytest.param("://example.org", id="no-scheme"),29 pytest.param("http://", id="no-host"),30 ],31)Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 32why, one step back32@pytest.mark.usefixtures("async_environment")Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
line 33why, one step back33async def test_get_invalid_url(server, url):Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 34–35why, one step back34 async with httpx.AsyncClient() as client:35 with pytest.raises(httpx.InvalidURL):Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef
line 36why, one step back36 await client.get(url)Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
lines 37–39why, one step back373839@pytest.mark.usefixtures("async_environment")Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
line 40why, one step back40async def test_build_request(server):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 41–42why, one step back41 url = server.url.copy_with(path="/echo_headers")42 headers = {"Custom-header": "value"}Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 43why, one step back43 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 44–53why, one step back44 request = client.build_request("GET", url)45 request.headers.update(headers)46 response = await client.send(request)4748 assert response.status_code == 20049 assert response.url == url5051 assert response.json()["Custom-header"] == "value"5253Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 54–55why, one step back54@pytest.mark.usefixtures("async_environment")55async def test_post(server):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
line 56why, one step back56 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 57why, one step back57 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 58–61why, one step back58 response = await client.post(url, data=b"Hello, world!")59 assert response.status_code == 2006061Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 62–63why, one step back62@pytest.mark.usefixtures("async_environment")63async def test_post_json(server):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
line 64why, one step back64 url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 65why, one step back65 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 66–69why, one step back66 response = await client.post(url, json={"text": "Hello, world!"})67 assert response.status_code == 2006869Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 70–71why, one step back70@pytest.mark.usefixtures("async_environment")71async def test_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:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
line 73why, one step back73 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 74why, one step back74 body = await response.aread()Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 75–80why, one step back7576 assert response.status_code == 20077 assert body == b"Hello, world!"78 assert response.content == b"Hello, world!"7980Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 81–82why, one step back81@pytest.mark.usefixtures("async_environment")82async def test_access_content_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 83why, one step back83 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 84–91why, one step back84 async with client.stream("GET", server.url) as response:85 pass8687 assert response.status_code == 20088 with pytest.raises(httpx.ResponseNotRead):89 response.content9091Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 92–93why, one step back92@pytest.mark.usefixtures("async_environment")93async def test_stream_request(server):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 94–97why, one step back94 async def hello_world():95 yield b"Hello, "96 yield b"world!"97Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 98why, one step back98 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 99–102why, one step back99 response = await client.request("POST", server.url, data=hello_world())100 assert response.status_code == 200101102Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 103–104why, one step back103@pytest.mark.usefixtures("async_environment")104async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 105why, one step back105 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 106–111why, one step back106 for status_code in (200, 400, 404, 500, 505):107 response = await client.request(108 "GET", server.url.copy_with(path=f"/status/{status_code}")109 )110111 if 400 <= status_code < 600:Raise HTTPStatusError in raise_from_status (#1072)François Voronbefore adoption27b0dbc
line 112why, one step back112 with pytest.raises(httpx.HTTPStatusError) as exc_info:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 113–115why, one step back113 response.raise_for_status()114 assert exc_info.value.response == response115 else:Fixed mypy errors in test_async_client.py and test_client.py (#985)Hasan Ramezanibefore adoption21d7e16
line 116why, one step back116 assert response.raise_for_status() is None # type: ignoreRename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 117–118why, one step back117118Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 119–120why, one step back119@pytest.mark.usefixtures("async_environment")120async def test_options(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 121why, one step back121 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 122–126why, one step back122 response = await client.options(server.url)123 assert response.status_code == 200124 assert response.text == "Hello, world!"125126Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 127–128why, one step back127@pytest.mark.usefixtures("async_environment")128async def test_head(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 129why, one step back129 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 130–134why, one step back130 response = await client.head(server.url)131 assert response.status_code == 200132 assert response.text == ""133134Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 135–136why, one step back135@pytest.mark.usefixtures("async_environment")136async def test_put(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 137why, one step back137 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 138–141why, one step back138 response = await client.put(server.url, data=b"Hello, world!")139 assert response.status_code == 200140141Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 142–143why, one step back142@pytest.mark.usefixtures("async_environment")143async def test_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 144why, one step back144 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 145–148why, one step back145 response = await client.patch(server.url, data=b"Hello, world!")146 assert response.status_code == 200147148Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 149–150why, one step back149@pytest.mark.usefixtures("async_environment")150async def test_delete(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 151why, one step back151 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 152–156why, one step back152 response = await client.delete(server.url)153 assert response.status_code == 200154 assert response.text == "Hello, world!"155156Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 157–158why, one step back157@pytest.mark.usefixtures("async_environment")158async def test_100_continue(server):Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 159–161why, one step back159 headers = {"Expect": "100-continue"}160 data = b"Echo request body"161Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 162why, one step back162 async with httpx.AsyncClient() as client:Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a
lines 163–168why, one step back163 response = await client.post(164 server.url.copy_with(path="/echo_body"), headers=headers, data=data165 )166167 assert response.status_code == 200168 assert response.content == data