test_client.py
This file
Path
tests/client/test_client.py
165 lines · 4.7 KiB · Python
Last changed by
Drop deprecated API (#1057)Tom Christiebefore adoption3f96e74
History of this fileTake it
The walk stopped after 200 commits: lines older than bc54dd0 point at it.
Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 1–7why, one step back1from datetime import timedelta23import pytest45import httpx67Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 8why, one step back8def test_get(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 9why, one step back9 url = server.urlReintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 10–11why, one step back10 with httpx.Client() as http:11 response = http.get(url)Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 12–24why, one step back12 assert response.status_code == 20013 assert response.url == url14 assert response.content == b"Hello, world!"15 assert response.text == "Hello, world!"16 assert response.http_version == "HTTP/1.1"17 assert response.encoding == "iso-8859-1"18 assert response.request.url == url19 assert response.headers20 assert response.is_redirect is False21 assert repr(response) == "<Response [200 OK]>"22 assert response.elapsed > timedelta(0)2324Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 25why, one step back25def test_build_request(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 26–28why, one step back26 url = server.url.copy_with(path="/echo_headers")27 headers = {"Custom-header": "value"}28Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 29why, one step back29 with httpx.Client() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 30–31why, one step back30 request = client.build_request("GET", url)31 request.headers.update(headers)Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 32why, one step back32 response = client.send(request)Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 33–39why, one step back3334 assert response.status_code == 20035 assert response.url == url3637 assert response.json()["Custom-header"] == "value"3839Add "Content-Length: 0" on POST, PUT, PATCH if required. (#995)Tom Christiebefore adoption7c8158a
lines 40–55why, one step back40def test_build_post_request(server):41 url = server.url.copy_with(path="/echo_headers")42 headers = {"Custom-header": "value"}4344 with httpx.Client() as client:45 request = client.build_request("POST", url)46 request.headers.update(headers)47 response = client.send(request)4849 assert response.status_code == 20050 assert response.url == url5152 assert response.json()["Content-length"] == "0"53 assert response.json()["Custom-header"] == "value"5455Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 56–58why, one step back56def test_post(server):57 with httpx.Client() as client:58 response = client.post(server.url, data=b"Hello, world!")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 59–62why, one step back59 assert response.status_code == 20060 assert response.reason_phrase == "OK"6162Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 63–65why, one step back63def test_post_json(server):64 with httpx.Client() as client:65 response = client.post(server.url, json={"text": "Hello, world!"})Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 66–69why, one step back66 assert response.status_code == 20067 assert response.reason_phrase == "OK"6869Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 70–73why, one step back70def test_stream_response(server):71 with httpx.Client() as client:72 with client.stream("GET", server.url) as response:73 content = response.read()Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 74–77why, one step back74 assert response.status_code == 20075 assert content == b"Hello, world!"7677Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 78why, one step back78def test_stream_iterator(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 79–80why, one step back79 body = b""80Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 81–83why, one step back81 with httpx.Client() as client:82 with client.stream("GET", server.url) as response:83 for chunk in response.iter_bytes():Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 84–89why, one step back84 body += chunk8586 assert response.status_code == 20087 assert body == b"Hello, world!"8889Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 90why, one step back90def test_raw_iterator(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 91–92why, one step back91 body = b""92Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 93–95why, one step back93 with httpx.Client() as client:94 with client.stream("GET", server.url) as response:95 for chunk in response.iter_raw():Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 96–101why, one step back96 body += chunk9798 assert response.status_code == 20099 assert body == b"Hello, world!"100101Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 102–103why, one step back102def test_raise_for_status(server):103 with httpx.Client() as client:Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 104why, one step back104 for status_code in (200, 400, 404, 500, 505):Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 105why, one step back105 response = client.request(Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
line 106why, one step back106 "GET", server.url.copy_with(path=f"/status/{status_code}")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 107–111why, one step back107 )108 if 400 <= status_code < 600:109 with pytest.raises(httpx.HTTPError) as exc_info:110 response.raise_for_status()111 assert exc_info.value.response == responseIncreased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210
line 112why, one step back112 assert exc_info.value.request.url.path == f"/status/{status_code}"Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 113why, one step back113 else:Fixed mypy errors in test_async_client.py and test_client.py (#985)Hasan Ramezanibefore adoption21d7e16
line 114why, one step back114 assert response.raise_for_status() is None # type: ignoreBackend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 115–116why, one step back115116Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 117–119why, one step back117def test_options(server):118 with httpx.Client() as client:119 response = client.options(server.url)Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 120–123why, one step back120 assert response.status_code == 200121 assert response.reason_phrase == "OK"122123Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 124–126why, one step back124def test_head(server):125 with httpx.Client() as client:126 response = client.head(server.url)Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 127–130why, one step back127 assert response.status_code == 200128 assert response.reason_phrase == "OK"129130Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 131–133why, one step back131def test_put(server):132 with httpx.Client() as client:133 response = client.put(server.url, data=b"Hello, world!")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 134–137why, one step back134 assert response.status_code == 200135 assert response.reason_phrase == "OK"136137Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 138–140why, one step back138def test_patch(server):139 with httpx.Client() as client:140 response = client.patch(server.url, data=b"Hello, world!")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 141–144why, one step back141 assert response.status_code == 200142 assert response.reason_phrase == "OK"143144Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 145–147why, one step back145def test_delete(server):146 with httpx.Client() as client:147 response = client.delete(server.url)Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 148–151why, one step back148 assert response.status_code == 200149 assert response.reason_phrase == "OK"150151Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 152why, one step back152def test_base_url(server):Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
line 153why, one step back153 base_url = server.urlReintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
lines 154–155why, one step back154 with httpx.Client(base_url=base_url) as client:155 response = client.get("/")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 156–160why, one step back156 assert response.status_code == 200157 assert response.url == base_url158159160def test_merge_url():Reintroduce sync API. (#735)Tom Christiebefore adoptionee37a76
line 161why, one step back161 client = httpx.Client(base_url="https://www.paypal.com/")Backend operations like .read(), .write() now have a manadatory timeout argument. (#611)Tom Christiebefore adoptionbc54dd0
lines 162–165why, one step back162 url = client.merge_url("http://www.paypal.com")163164 assert url.scheme == "https"165 assert url.is_ssl