test_client.py
This file
Path
tests/client/test_client.py
194 lines · 5.7 KiB · Python
Last changed by
Add aiter methods on response (#610)Tom Christiebefore adoptionec40d04
History of this fileTake it
The walk stopped after 200 commits: lines older than e64fcad point at it.
Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 1–3why, one step back1from datetime import timedelta2from time import sleep3Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 4–8why, one step back4import pytest56import httpx78Drop sync (#544)Tom Christiebefore adoption206c537
lines 9–10why, one step back9@pytest.mark.asyncio10async def test_get(server):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 11why, one step back11 url = server.urlDrop sync (#544)Tom Christiebefore adoption206c537
lines 12–13why, one step back12 async with httpx.Client() as http:13 response = await http.get(url)Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
line 14why, one step back14 assert response.status_code == 200Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 15why, one step back15 assert response.url == urlAdd --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 16–17why, one step back16 assert response.content == b"Hello, world!"17 assert response.text == "Hello, world!"Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3
line 18why, one step back18 assert response.http_version == "HTTP/1.1"Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
line 19why, one step back19 assert response.encoding == "iso-8859-1"Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 20why, one step back20 assert response.request.url == urlAdd --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 21–23why, one step back21 assert response.headers22 assert response.is_redirect is False23 assert repr(response) == "<Response [200 OK]>"Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
line 24why, one step back24 assert response.elapsed > timedelta(0)Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 25–26why, one step back2526Drop sync (#544)Tom Christiebefore adoption206c537
lines 27–28why, one step back27@pytest.mark.asyncio28async def test_build_request(server):Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
lines 29–31why, one step back29 url = server.url.copy_with(path="/echo_headers")30 headers = {"Custom-header": "value"}31Drop sync (#544)Tom Christiebefore adoption206c537
lines 32–33why, one step back32 async with httpx.Client() as client:33 request = client.build_request("GET", url)Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
line 34why, one step back34 request.headers.update(headers)Drop sync (#544)Tom Christiebefore adoption206c537
line 35why, one step back35 response = await client.send(request)Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
lines 36–42why, one step back3637 assert response.status_code == 20038 assert response.url == url3940 assert response.json()["Custom-header"] == "value"4142Drop sync (#544)Tom Christiebefore adoption206c537
lines 43–46why, one step back43@pytest.mark.asyncio44async def test_post(server):45 async with httpx.Client() as client:46 response = await client.post(server.url, data=b"Hello, world!")Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 47–50why, one step back47 assert response.status_code == 20048 assert response.reason_phrase == "OK"4950Drop sync (#544)Tom Christiebefore adoption206c537
lines 51–54why, one step back51@pytest.mark.asyncio52async def test_post_json(server):53 async with httpx.Client() as client:54 response = await client.post(server.url, json={"text": "Hello, world!"})Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 55–58why, one step back55 assert response.status_code == 20056 assert response.reason_phrase == "OK"5758Drop sync (#544)Tom Christiebefore adoption206c537
lines 59–61why, one step back59@pytest.mark.asyncio60async def test_stream_response(server):61 async with httpx.Client() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 62–63why, one step back62 async with client.stream("GET", server.url) as response:63 content = await response.read()Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 64–67why, one step back64 assert response.status_code == 20065 assert content == b"Hello, world!"6667Drop sync (#544)Tom Christiebefore adoption206c537
lines 68–69why, one step back68@pytest.mark.asyncio69async def test_stream_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 70–71why, one step back70 body = b""71Drop sync (#544)Tom Christiebefore adoption206c537
line 72why, one step back72 async with httpx.Client() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 73why, one step back73 async with client.stream("GET", server.url) as response:Add aiter methods on response (#610)Tom Christiebefore adoptionec40d04
line 74why, one step back74 async for chunk in response.aiter_bytes():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 75–76why, one step back75 body += chunk76Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 77–80why, one step back77 assert response.status_code == 20078 assert body == b"Hello, world!"7980Drop sync (#544)Tom Christiebefore adoption206c537
lines 81–82why, one step back81@pytest.mark.asyncio82async def test_raw_iterator(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 83–84why, one step back83 body = b""84Drop sync (#544)Tom Christiebefore adoption206c537
line 85why, one step back85 async with httpx.Client() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 86why, one step back86 async with client.stream("GET", server.url) as response:Add aiter methods on response (#610)Tom Christiebefore adoptionec40d04
line 87why, one step back87 async for chunk in response.aiter_raw():Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 88–89why, one step back88 body += chunk89Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 90–93why, one step back90 assert response.status_code == 20091 assert body == b"Hello, world!"9293Drop sync (#544)Tom Christiebefore adoption206c537
lines 94–96why, one step back94@pytest.mark.asyncio95async def test_raise_for_status(server):96 async with httpx.Client() as client:Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
line 97why, one step back97 for status_code in (200, 400, 404, 500, 505):Drop sync (#544)Tom Christiebefore adoption206c537
line 98why, one step back98 response = await client.request(Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 99why, one step back99 "GET", server.url.copy_with(path="/status/{}".format(status_code))Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 100–101why, one step back100 )101 if 400 <= status_code < 600:Make HTTPError importable from the top-level (#421)Josep Cugatbefore adoptiona028256
line 102why, one step back102 with pytest.raises(httpx.HTTPError) as exc_info:Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 103–108why, one step back103 response.raise_for_status()104 assert exc_info.value.response == response105 else:106 assert response.raise_for_status() is None107108Drop sync (#544)Tom Christiebefore adoption206c537
lines 109–112why, one step back109@pytest.mark.asyncio110async def test_options(server):111 async with httpx.Client() as client:112 response = await client.options(server.url)Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 113–116why, one step back113 assert response.status_code == 200114 assert response.reason_phrase == "OK"115116Drop sync (#544)Tom Christiebefore adoption206c537
lines 117–120why, one step back117@pytest.mark.asyncio118async def test_head(server):119 async with httpx.Client() as client:120 response = await client.head(server.url)Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 121–124why, one step back121 assert response.status_code == 200122 assert response.reason_phrase == "OK"123124Drop sync (#544)Tom Christiebefore adoption206c537
lines 125–128why, one step back125@pytest.mark.asyncio126async def test_put(server):127 async with httpx.Client() as client:128 response = await client.put(server.url, data=b"Hello, world!")Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 129–132why, one step back129 assert response.status_code == 200130 assert response.reason_phrase == "OK"131132Drop sync (#544)Tom Christiebefore adoption206c537
lines 133–136why, one step back133@pytest.mark.asyncio134async def test_patch(server):135 async with httpx.Client() as client:136 response = await client.patch(server.url, data=b"Hello, world!")Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 137–140why, one step back137 assert response.status_code == 200138 assert response.reason_phrase == "OK"139140Drop sync (#544)Tom Christiebefore adoption206c537
lines 141–144why, one step back141@pytest.mark.asyncio142async def test_delete(server):143 async with httpx.Client() as client:144 response = await client.delete(server.url)Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 145–148why, one step back145 assert response.status_code == 200146 assert response.reason_phrase == "OK"147148Drop sync (#544)Tom Christiebefore adoption206c537
lines 149–150why, one step back149@pytest.mark.asyncio150async def test_base_url(server):Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 151why, one step back151 base_url = server.urlDrop sync (#544)Tom Christiebefore adoption206c537
lines 152–153why, one step back152 async with httpx.Client(base_url=base_url) as client:153 response = await client.get("/")Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
line 154why, one step back154 assert response.status_code == 200Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 155why, one step back155 assert response.url == base_urlAdd --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 156–157why, one step back156157Drop sync (#544)Tom Christiebefore adoption206c537
lines 158–159why, one step back158@pytest.mark.asyncio159async def test_uds(uds_server):Add support for unix domain sockets (#511)Jonas Lundbergbefore adoption7a96a2c
lines 160–162why, one step back160 url = uds_server.url161 uds = uds_server.config.uds162 assert uds is not NoneDrop sync (#544)Tom Christiebefore adoption206c537
lines 163–164why, one step back163 async with httpx.Client(uds=uds) as client:164 response = await client.get(url)Add support for unix domain sockets (#511)Jonas Lundbergbefore adoption7a96a2c
lines 165–169why, one step back165 assert response.status_code == 200166 assert response.text == "Hello, world!"167 assert response.encoding == "iso-8859-1"168169Add --diff flag to Black for easier debugging (#219)euri10before adoptione64fcad
lines 170–175why, one step back170def test_merge_url():171 client = httpx.Client(base_url="https://www.paypal.com/")172 url = client.merge_url("http://www.paypal.com")173174 assert url.scheme == "https"175 assert url.is_sslEnforce that sync client uses asyncio-based backend (#232)Florimond Mancabefore adoption9c7d23c
lines 176–177why, one step back176177Drop sync (#544)Tom Christiebefore adoption206c537
lines 178–179why, one step back178@pytest.mark.asyncio179async def test_elapsed_delay(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 180why, one step back180 url = server.url.copy_with(path="/slow_response/100")Drop sync (#544)Tom Christiebefore adoption206c537
line 181why, one step back181 async with httpx.Client() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 182why, one step back182 response = await client.get(url)Fix flaky Response.elapsed tests (#446)Florimond Mancabefore adoption24346e2
line 183why, one step back183 assert response.elapsed.total_seconds() == pytest.approx(0.1, rel=0.2)Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 184–185why, one step back184185Drop sync (#544)Tom Christiebefore adoption206c537
lines 186–187why, one step back186@pytest.mark.asyncio187async def test_elapsed_delay_ignores_read_time(server):Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
line 188why, one step back188 url = server.url.copy_with(path="/slow_response/100")Drop sync (#544)Tom Christiebefore adoption206c537
line 189why, one step back189 async with httpx.Client() as client:Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
lines 190–193why, one step back190 async with client.stream("GET", url) as response:191 sleep(0.2)192 await response.read()193Fix flaky Response.elapsed tests (#446)Florimond Mancabefore adoption24346e2
line 194why, one step back194 assert response.elapsed.total_seconds() == pytest.approx(0.1, rel=0.2)