Skip to content
Myr

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 file

Take 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 back
1from datetime import timedelta
23import pytest45import httpx67

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 8–9why, one step back
8@pytest.mark.usefixtures("async_environment")
9async def test_get(server):

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

line 10why, one step back
10 url = server.url

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 11why, one step back
11 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 12–19why, one step back
12 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)19

Full coverage, with exception of URLLib3Transport (#1086)Tom Christiebefore adoption2d491c9

lines 20–22why, one step back
20 with pytest.raises(httpx.NotRedirectResponse):
21 await response.anext()22

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

line 23why, one step back
23

Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef

lines 24–31why, one step back
24@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 back
32@pytest.mark.usefixtures("async_environment")

Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef

line 33why, one step back
33async def test_get_invalid_url(server, url):

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 34–35why, one step back
34 async with httpx.AsyncClient() as client:
35 with pytest.raises(httpx.InvalidURL):

Parameterize invalid URL tests (#1079)Tom Christiebefore adoption696c1ef

line 36why, one step back
36 await client.get(url)

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 37–39why, one step back
37
3839@pytest.mark.usefixtures("async_environment")

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

line 40why, one step back
40async def test_build_request(server):

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 41–42why, one step back
41 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 back
43 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 44–53why, one step back
44 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"5253

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 54–55why, one step back
54@pytest.mark.usefixtures("async_environment")
55async def test_post(server):

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

line 56why, one step back
56 url = server.url

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 57why, one step back
57 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 58–61why, one step back
58 response = await client.post(url, data=b"Hello, world!")
59 assert response.status_code == 2006061

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 62–63why, one step back
62@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 back
64 url = server.url

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 65why, one step back
65 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 66–69why, one step back
66 response = await client.post(url, json={"text": "Hello, world!"})
67 assert response.status_code == 2006869

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 70–71why, one step back
70@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 back
72 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

line 73why, one step back
73 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 back
74 body = await response.aread()

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 75–80why, one step back
75
76 assert response.status_code == 20077 assert body == b"Hello, world!"78 assert response.content == b"Hello, world!"7980

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 81–82why, one step back
81@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 back
83 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 84–91why, one step back
84 async with client.stream("GET", server.url) as response:
85 pass8687 assert response.status_code == 20088 with pytest.raises(httpx.ResponseNotRead):89 response.content9091

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 92–93why, one step back
92@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 back
94 async def hello_world():
95 yield b"Hello, "96 yield b"world!"97

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 98why, one step back
98 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 99–102why, one step back
99 response = await client.request("POST", server.url, data=hello_world())
100 assert response.status_code == 200101102

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 103–104why, one step back
103@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 back
105 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 106–111why, one step back
106 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 back
112 with pytest.raises(httpx.HTTPStatusError) as exc_info:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 113–115why, one step back
113 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 back
116 assert response.raise_for_status() is None # type: ignore

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 117–118why, one step back
117
118

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 119–120why, one step back
119@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 back
121 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 122–126why, one step back
122 response = await client.options(server.url)
123 assert response.status_code == 200124 assert response.text == "Hello, world!"125126

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 127–128why, one step back
127@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 back
129 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 130–134why, one step back
130 response = await client.head(server.url)
131 assert response.status_code == 200132 assert response.text == ""133134

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 135–136why, one step back
135@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 back
137 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 138–141why, one step back
138 response = await client.put(server.url, data=b"Hello, world!")
139 assert response.status_code == 200140141

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 142–143why, one step back
142@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 back
144 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 145–148why, one step back
145 response = await client.patch(server.url, data=b"Hello, world!")
146 assert response.status_code == 200147148

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 149–150why, one step back
149@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 back
151 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 152–156why, one step back
152 response = await client.delete(server.url)
153 assert response.status_code == 200154 assert response.text == "Hello, world!"155156

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 157–158why, one step back
157@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 back
159 headers = {"Expect": "100-continue"}
160 data = b"Echo request body"161

Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84

line 162why, one step back
162 async with httpx.AsyncClient() as client:

Rename `concurrency` directory to `backends` (#662)Andrés Álvarezbefore adoptione34df7a

lines 163–168why, one step back
163 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