test_client.py
This file
Path
tests/client/test_client.py
182 lines · 5.4 KiB · Python
Last changed by
Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
History of this fileTake it
The walk stopped after 200 commits: lines older than 0fa55bb point at it.
Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 1–7why, one step back1from datetime import timedelta23import pytest45import httpx67Drop sync (#544)Tom Christiebefore adoption206c537
lines 8–9why, one step back8@pytest.mark.asyncio9async def test_get(server):Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
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 http:Drop sync (#544)Tom Christiebefore adoption206c537
line 12why, one step back12 response = await http.get(url)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 13–25why, one step back13 assert response.status_code == 20014 assert response.url == url15 assert response.content == b"Hello, world!"16 assert response.text == "Hello, world!"17 assert response.http_version == "HTTP/1.1"18 assert response.encoding == "iso-8859-1"19 assert response.request.url == url20 assert response.headers21 assert response.is_redirect is False22 assert repr(response) == "<Response [200 OK]>"23 assert response.elapsed > timedelta(0)2425Drop sync (#544)Tom Christiebefore adoption206c537
lines 26–27why, one step back26@pytest.mark.asyncio27async def test_build_request(server):Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 28–30why, one step back28 url = server.url.copy_with(path="/echo_headers")29 headers = {"Custom-header": "value"}30Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 31why, one step back31 async with httpx.AsyncClient() as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 32why, one step back32 request = client.build_request("GET", url)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
line 33why, one step back33 request.headers.update(headers)Drop sync (#544)Tom Christiebefore adoption206c537
line 34why, one step back34 response = await client.send(request)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 35–41why, one step back3536 assert response.status_code == 20037 assert response.url == url3839 assert response.json()["Custom-header"] == "value"4041Drop sync (#544)Tom Christiebefore adoption206c537
lines 42–43why, one step back42@pytest.mark.asyncio43async def test_post(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 44why, one step back44 async with httpx.AsyncClient() as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 45why, one step back45 response = await client.post(server.url, data=b"Hello, world!")Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 46–49why, one step back46 assert response.status_code == 20047 assert response.reason_phrase == "OK"4849Drop sync (#544)Tom Christiebefore adoption206c537
lines 50–51why, one step back50@pytest.mark.asyncio51async def test_post_json(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 52why, one step back52 async with httpx.AsyncClient() as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 53why, one step back53 response = await client.post(server.url, json={"text": "Hello, world!"})Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 54–57why, one step back54 assert response.status_code == 20055 assert response.reason_phrase == "OK"5657Drop sync (#544)Tom Christiebefore adoption206c537
lines 58–59why, one step back58@pytest.mark.asyncio59async def test_stream_response(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 60why, one step back60 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 61why, one step back61 async with client.stream("GET", server.url) as response:Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 62why, one step back62 content = await response.aread()Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 63–66why, one step back63 assert response.status_code == 20064 assert content == b"Hello, world!"6566Drop sync (#544)Tom Christiebefore adoption206c537
lines 67–68why, one step back67@pytest.mark.asyncio68async def test_stream_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 69–70why, one step back69 body = b""70Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 71why, one step back71 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 72why, one step back72 async with client.stream("GET", server.url) as response:Add aiter methods on response (#610)Tom Christiebefore adoptionec40d04
line 73why, one step back73 async for chunk in response.aiter_bytes():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 74–75why, one step back74 body += chunk75Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 76–79why, one step back76 assert response.status_code == 20077 assert body == b"Hello, world!"7879Drop sync (#544)Tom Christiebefore adoption206c537
lines 80–81why, one step back80@pytest.mark.asyncio81async def test_raw_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 82–83why, one step back82 body = b""83Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 84why, one step back84 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 85why, one step back85 async with client.stream("GET", server.url) as response:Add aiter methods on response (#610)Tom Christiebefore adoptionec40d04
line 86why, one step back86 async for chunk in response.aiter_raw():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 87–88why, one step back87 body += chunk88Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 89–92why, one step back89 assert response.status_code == 20090 assert body == b"Hello, world!"9192Drop sync (#544)Tom Christiebefore adoption206c537
lines 93–94why, one step back93@pytest.mark.asyncio94async def test_raise_for_status(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 95why, one step back95 async with httpx.AsyncClient() as client:Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
line 96why, one step back96 for status_code in (200, 400, 404, 500, 505):Drop sync (#544)Tom Christiebefore adoption206c537
line 97why, one step back97 response = await client.request(Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 98–100why, one step back98 "GET", server.url.copy_with(path="/status/{}".format(status_code))99 )100 if 400 <= status_code < 600:Make HTTPError importable from the top-level (#421)Josep Cugatbefore adoptiona028256
line 101why, one step back101 with pytest.raises(httpx.HTTPError) as exc_info:Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 102–107why, one step back102 response.raise_for_status()103 assert exc_info.value.response == response104 else:105 assert response.raise_for_status() is None106107Drop sync (#544)Tom Christiebefore adoption206c537
lines 108–109why, one step back108@pytest.mark.asyncio109async 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 sync (#544)Tom Christiebefore adoption206c537
line 111why, one step back111 response = await client.options(server.url)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 112–115why, one step back112 assert response.status_code == 200113 assert response.reason_phrase == "OK"114115Drop sync (#544)Tom Christiebefore adoption206c537
lines 116–117why, one step back116@pytest.mark.asyncio117async 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 sync (#544)Tom Christiebefore adoption206c537
line 119why, one step back119 response = await client.head(server.url)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 120–123why, one step back120 assert response.status_code == 200121 assert response.reason_phrase == "OK"122123Drop sync (#544)Tom Christiebefore adoption206c537
lines 124–125why, one step back124@pytest.mark.asyncio125async 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 sync (#544)Tom Christiebefore adoption206c537
line 127why, one step back127 response = await client.put(server.url, data=b"Hello, world!")Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 128–131why, one step back128 assert response.status_code == 200129 assert response.reason_phrase == "OK"130131Drop sync (#544)Tom Christiebefore adoption206c537
lines 132–133why, one step back132@pytest.mark.asyncio133async def test_patch(server):Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 134why, one step back134 async with httpx.AsyncClient() as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 135why, one step back135 response = await client.patch(server.url, data=b"Hello, world!")Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 136–139why, one step back136 assert response.status_code == 200137 assert response.reason_phrase == "OK"138139Drop sync (#544)Tom Christiebefore adoption206c537
lines 140–141why, one step back140@pytest.mark.asyncio141async 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:Drop sync (#544)Tom Christiebefore adoption206c537
line 143why, one step back143 response = await client.delete(server.url)Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 144–147why, one step back144 assert response.status_code == 200145 assert response.reason_phrase == "OK"146147Drop sync (#544)Tom Christiebefore adoption206c537
lines 148–149why, one step back148@pytest.mark.asyncio149async def test_base_url(server):Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
line 150why, one step back150 base_url = server.urlRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 151why, one step back151 async with httpx.AsyncClient(base_url=base_url) as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 152why, one step back152 response = await client.get("/")Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 153–156why, one step back153 assert response.status_code == 200154 assert response.url == base_url155156Drop sync (#544)Tom Christiebefore adoption206c537
lines 157–158why, one step back157@pytest.mark.asyncio158async def test_uds(uds_server):Add support for unix domain sockets (#511)Jonas Lundbergbefore adoption7a96a2c
lines 159–161why, one step back159 url = uds_server.url160 uds = uds_server.config.uds161 assert uds is not NoneRename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 162why, one step back162 async with httpx.AsyncClient(uds=uds) as client:Drop sync (#544)Tom Christiebefore adoption206c537
line 163why, one step back163 response = await client.get(url)Add support for unix domain sockets (#511)Jonas Lundbergbefore adoption7a96a2c
lines 164–168why, one step back164 assert response.status_code == 200165 assert response.text == "Hello, world!"166 assert response.encoding == "iso-8859-1"167168Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
line 169why, one step back169def test_merge_url():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 170why, one step back170 client = httpx.AsyncClient(base_url="https://www.paypal.com/")Add debug logging to SSLConfig (#378)Seth Michael Larsonbefore adoption0fa55bb
lines 171–176why, one step back171 url = client.merge_url("http://www.paypal.com")172173 assert url.scheme == "https"174 assert url.is_ssl175176Drop sync (#544)Tom Christiebefore adoption206c537
lines 177–178why, one step back177@pytest.mark.asyncio178async def test_elapsed_delay(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 179why, one step back179 url = server.url.copy_with(path="/slow_response/100")Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 180why, one step back180 async with httpx.AsyncClient() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 181why, one step back181 response = await client.get(url)Trivial-case test for response.elapsedTom Christiebefore adoption02d16bf
line 182why, one step back182 assert response.elapsed.total_seconds() > 0.0