test_client.py
This file
Path
tests/client/test_client.py
182 lines · 5.3 KiB · Python
Last changed by
Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
History of this fileTake it
The walk stopped after 200 commits: lines older than cbe7616 point at it.
Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 1–2why, one step back1from datetime import timedelta2Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 3–7why, one step back3import pytest45import httpx67Drop sync (#544)Tom Christiebefore adoption206c537
lines 8–9why, one step back8@pytest.mark.asyncio9async def test_get(server):Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
line 10why, one step back10 url = server.urlDrop sync (#544)Tom Christiebefore adoption206c537
lines 11–12why, one step back11 async with httpx.Client() as http:12 response = await http.get(url)Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 13–22why, 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]>"Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
line 23why, one step back23 assert response.elapsed > timedelta(0)Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 24–25why, one step back2425Drop sync (#544)Tom Christiebefore adoption206c537
lines 26–27why, one step back26@pytest.mark.asyncio27async def test_build_request(server):Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
lines 28–30why, one step back28 url = server.url.copy_with(path="/echo_headers")29 headers = {"Custom-header": "value"}30Drop sync (#544)Tom Christiebefore adoption206c537
lines 31–32why, one step back31 async with httpx.Client() as client:32 request = client.build_request("GET", url)Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
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 `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
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–45why, one step back42@pytest.mark.asyncio43async def test_post(server):44 async with httpx.Client() as client:45 response = await client.post(server.url, data=b"Hello, world!")Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 46–49why, one step back46 assert response.status_code == 20047 assert response.reason_phrase == "OK"4849Drop sync (#544)Tom Christiebefore adoption206c537
lines 50–53why, one step back50@pytest.mark.asyncio51async def test_post_json(server):52 async with httpx.Client() as client:53 response = await client.post(server.url, json={"text": "Hello, world!"})Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 54–57why, one step back54 assert response.status_code == 20055 assert response.reason_phrase == "OK"5657Drop sync (#544)Tom Christiebefore adoption206c537
lines 58–60why, one step back58@pytest.mark.asyncio59async def test_stream_response(server):60 async with httpx.Client() 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()Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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""70Drop sync (#544)Tom Christiebefore adoption206c537
line 71why, one step back71 async with httpx.Client() 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 += chunk75Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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""83Drop sync (#544)Tom Christiebefore adoption206c537
line 84why, one step back84 async with httpx.Client() 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 += chunk88Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 89–92why, one step back89 assert response.status_code == 20090 assert body == b"Hello, world!"9192Drop sync (#544)Tom Christiebefore adoption206c537
lines 93–95why, one step back93@pytest.mark.asyncio94async def test_raise_for_status(server):95 async with httpx.Client() as client:Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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(Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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:Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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–111why, one step back108@pytest.mark.asyncio109async def test_options(server):110 async with httpx.Client() as client:111 response = await client.options(server.url)Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 112–115why, one step back112 assert response.status_code == 200113 assert response.reason_phrase == "OK"114115Drop sync (#544)Tom Christiebefore adoption206c537
lines 116–119why, one step back116@pytest.mark.asyncio117async def test_head(server):118 async with httpx.Client() as client:119 response = await client.head(server.url)Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 120–123why, one step back120 assert response.status_code == 200121 assert response.reason_phrase == "OK"122123Drop sync (#544)Tom Christiebefore adoption206c537
lines 124–127why, one step back124@pytest.mark.asyncio125async def test_put(server):126 async with httpx.Client() as client:127 response = await client.put(server.url, data=b"Hello, world!")Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 128–131why, one step back128 assert response.status_code == 200129 assert response.reason_phrase == "OK"130131Drop sync (#544)Tom Christiebefore adoption206c537
lines 132–135why, one step back132@pytest.mark.asyncio133async def test_patch(server):134 async with httpx.Client() as client:135 response = await client.patch(server.url, data=b"Hello, world!")Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 136–139why, one step back136 assert response.status_code == 200137 assert response.reason_phrase == "OK"138139Drop sync (#544)Tom Christiebefore adoption206c537
lines 140–143why, one step back140@pytest.mark.asyncio141async def test_delete(server):142 async with httpx.Client() as client:143 response = await client.delete(server.url)Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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):Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
line 150why, one step back150 base_url = server.urlDrop sync (#544)Tom Christiebefore adoption206c537
lines 151–152why, one step back151 async with httpx.Client(base_url=base_url) as client:152 response = await client.get("/")Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
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 NoneDrop sync (#544)Tom Christiebefore adoption206c537
lines 162–163why, one step back162 async with httpx.Client(uds=uds) as client:163 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"167168Merge pull request #314 from dobrovolsky/drop_npnTom Christiebefore adoptioncbe7616
lines 169–176why, one step back169def test_merge_url():170 client = httpx.Client(base_url="https://www.paypal.com/")171 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")Drop sync (#544)Tom Christiebefore adoption206c537
line 180why, one step back180 async with httpx.Client() 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