test_responses.py
This file
Path
tests/models/test_responses.py
590 lines · 14.8 KiB · Python
Last changed by
Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
History of this fileTake it
The walk stopped after 200 commits: lines older than 50d337e point at it.
When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 1–4why, one step back1import datetime2import json3from unittest import mock4Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 5why, one step back5import brotliWhen setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 6–21why, one step back6import pytest78import httpx9from httpx._content_streams import AsyncIteratorStream, IteratorStream101112def streaming_body():13 yield b"Hello, "14 yield b"world!"151617async def async_streaming_body():18 yield b"Hello, "19 yield b"world!"2021Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 22why, one step back22def test_response():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 23–27why, one step back23 response = httpx.Response(24 200,25 content=b"Hello, world!",26 request=httpx.Request("GET", "https://example.org"),27 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 28–31why, one step back2829 assert response.status_code == 20030 assert response.reason_phrase == "OK"31 assert response.text == "Hello, world!"Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 32–33why, one step back32 assert response.request.method == "GET"33 assert response.request.url == "https://example.org"When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 34–37why, one step back34 assert response.elapsed >= datetime.timedelta(0)35 assert not response.is_error3637Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 38why, one step back38def test_raise_for_status():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 39–40why, one step back39 request = httpx.Request("GET", "https://example.org")40Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 41why, one step back41 # 2xx status codes are not an error.Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
line 42why, one step back42 response = httpx.Response(200, request=request)Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 43–45why, one step back43 response.raise_for_status()4445 # 4xx status codes are a client error.Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
line 46why, one step back46 response = httpx.Response(403, request=request)Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 47–50why, one step back47 with pytest.raises(httpx.HTTPStatusError):48 response.raise_for_status()4950 # 5xx status codes are a server error.Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
line 51why, one step back51 response = httpx.Response(500, request=request)Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 52–61why, one step back52 with pytest.raises(httpx.HTTPStatusError):53 response.raise_for_status()5455 # Calling .raise_for_status without setting a request instance is56 # not valid. Should raise a runtime error.57 response = httpx.Response(200)58 with pytest.raises(RuntimeError):59 response.raise_for_status()6061When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
line 62why, one step back62def test_response_repr():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 63–66why, one step back63 response = httpx.Response(64 200,65 content=b"Hello, world!",66 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 67–75why, one step back67 assert repr(response) == "<Response [200 OK]>"686970def test_response_content_type_encoding():71 """72 Use the charset encoding in the Content-Type header if possible.73 """74 headers = {"Content-Type": "text-plain; charset=latin-1"}75 content = "Latin 1: ÿ".encode("latin-1")Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 76–80why, one step back76 response = httpx.Response(77 200,78 content=content,79 headers=headers,80 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 81–89why, one step back81 assert response.text == "Latin 1: ÿ"82 assert response.encoding == "latin-1"838485def test_response_autodetect_encoding():86 """87 Autodetect encoding if there is no charset info in a Content-Type header.88 """89 content = "おはようございます。".encode("EUC-JP")Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 90–93why, one step back90 response = httpx.Response(91 200,92 content=content,93 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 94–103why, one step back94 assert response.text == "おはようございます。"95 assert response.encoding == "EUC-JP"969798def test_response_fallback_to_autodetect():99 """100 Fallback to autodetection if we get an invalid charset in the Content-Type header.101 """102 headers = {"Content-Type": "text-plain; charset=invalid-codec-name"}103 content = "おはようございます。".encode("EUC-JP")Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 104–108why, one step back104 response = httpx.Response(105 200,106 content=content,107 headers=headers,108 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 109–119why, one step back109 assert response.text == "おはようございます。"110 assert response.encoding == "EUC-JP"111112113def test_response_default_text_encoding():114 """115 A media type of 'text/*' with no charset should default to ISO-8859-1.116 See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1117 """118 content = b"Hello, world!"119 headers = {"Content-Type": "text/plain"}Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 120–124why, one step back120 response = httpx.Response(121 200,122 content=content,123 headers=headers,124 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 125–133why, one step back125 assert response.status_code == 200126 assert response.encoding == "iso-8859-1"127 assert response.text == "Hello, world!"128129130def test_response_default_encoding():131 """132 Default to utf-8 if all else fails.133 """Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 134–137why, one step back134 response = httpx.Response(135 200,136 content=b"",137 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 138–146why, one step back138 assert response.text == ""139 assert response.encoding == "utf-8"140141142def test_response_non_text_encoding():143 """144 Default to apparent encoding for non-text content-type headers.145 """146 headers = {"Content-Type": "image/png"}Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 147–151why, one step back147 response = httpx.Response(148 200,149 content=b"xyz",150 headers=headers,151 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 152–160why, one step back152 assert response.text == "xyz"153 assert response.encoding == "ascii"154155156def test_response_set_explicit_encoding():157 headers = {158 "Content-Type": "text-plain; charset=utf-8"159 } # Deliberately incorrect charset160 response = httpx.Response(Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 161–163why, one step back161 200,162 content="Latin 1: ÿ".encode("latin-1"),163 headers=headers,When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 164–171why, one step back164 )165 response.encoding = "latin-1"166 assert response.text == "Latin 1: ÿ"167 assert response.encoding == "latin-1"168169170def test_response_force_encoding():171 response = httpx.Response(Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 172–173why, one step back172 200,173 content="Snowman: ☃".encode("utf-8"),When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 174–182why, one step back174 )175 response.encoding = "iso-8859-1"176 assert response.status_code == 200177 assert response.reason_phrase == "OK"178 assert response.text == "Snowman: â\x98\x83"179 assert response.encoding == "iso-8859-1"180181182def test_read():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 183–186why, one step back183 response = httpx.Response(184 200,185 content=b"Hello, world!",186 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 187–201why, one step back187188 assert response.status_code == 200189 assert response.text == "Hello, world!"190 assert response.encoding == "ascii"191 assert response.is_closed192193 content = response.read()194195 assert content == b"Hello, world!"196 assert response.content == b"Hello, world!"197 assert response.is_closed198199200@pytest.mark.asyncio201async def test_aread():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 202–205why, one step back202 response = httpx.Response(203 200,204 content=b"Hello, world!",205 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 206–220why, one step back206207 assert response.status_code == 200208 assert response.text == "Hello, world!"209 assert response.encoding == "ascii"210 assert response.is_closed211212 content = await response.aread()213214 assert content == b"Hello, world!"215 assert response.content == b"Hello, world!"216 assert response.is_closed217218219def test_iter_raw():220 stream = IteratorStream(iterator=streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 221–224why, one step back221 response = httpx.Response(222 200,223 stream=stream,224 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 225–234why, one step back225226 raw = b""227 for part in response.iter_raw():228 raw += part229 assert raw == b"Hello, world!"230231232@pytest.mark.asyncio233async def test_aiter_raw():234 stream = AsyncIteratorStream(aiterator=async_streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 235–238why, one step back235 response = httpx.Response(236 200,237 stream=stream,238 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 239–246why, one step back239240 raw = b""241 async for part in response.aiter_raw():242 raw += part243 assert raw == b"Hello, world!"244245246def test_iter_bytes():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 247–250why, one step back247 response = httpx.Response(248 200,249 content=b"Hello, world!",250 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 251–259why, one step back251252 content = b""253 for part in response.iter_bytes():254 content += part255 assert content == b"Hello, world!"256257258@pytest.mark.asyncio259async def test_aiter_bytes():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 260–263why, one step back260 response = httpx.Response(261 200,262 content=b"Hello, world!",263 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 264–271why, one step back264265 content = b""266 async for part in response.aiter_bytes():267 content += part268 assert content == b"Hello, world!"269270271def test_iter_text():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 272–275why, one step back272 response = httpx.Response(273 200,274 content=b"Hello, world!",275 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 276–284why, one step back276277 content = ""278 for part in response.iter_text():279 content += part280 assert content == "Hello, world!"281282283@pytest.mark.asyncio284async def test_aiter_text():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 285–288why, one step back285 response = httpx.Response(286 200,287 content=b"Hello, world!",288 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 289–296why, one step back289290 content = ""291 async for part in response.aiter_text():292 content += part293 assert content == "Hello, world!"294295296def test_iter_lines():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 297–300why, one step back297 response = httpx.Response(298 200,299 content=b"Hello,\nworld!",300 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 301–309why, one step back301302 content = []303 for line in response.iter_lines():304 content.append(line)305 assert content == ["Hello,\n", "world!"]306307308@pytest.mark.asyncio309async def test_aiter_lines():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 310–313why, one step back310 response = httpx.Response(311 200,312 content=b"Hello,\nworld!",313 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 314–322why, one step back314315 content = []316 async for line in response.aiter_lines():317 content.append(line)318 assert content == ["Hello,\n", "world!"]319320321def test_sync_streaming_response():322 stream = IteratorStream(iterator=streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 323–326why, one step back323 response = httpx.Response(324 200,325 stream=stream,326 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 327–340why, one step back327328 assert response.status_code == 200329 assert not response.is_closed330331 content = response.read()332333 assert content == b"Hello, world!"334 assert response.content == b"Hello, world!"335 assert response.is_closed336337338@pytest.mark.asyncio339async def test_async_streaming_response():340 stream = AsyncIteratorStream(aiterator=async_streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 341–344why, one step back341 response = httpx.Response(342 200,343 stream=stream,344 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 345–357why, one step back345346 assert response.status_code == 200347 assert not response.is_closed348349 content = await response.aread()350351 assert content == b"Hello, world!"352 assert response.content == b"Hello, world!"353 assert response.is_closed354355356def test_cannot_read_after_stream_consumed():357 stream = IteratorStream(iterator=streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 358–361why, one step back358 response = httpx.Response(359 200,360 stream=stream,361 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 362–373why, one step back362363 content = b""364 for part in response.iter_bytes():365 content += part366367 with pytest.raises(httpx.StreamConsumed):368 response.read()369370371@pytest.mark.asyncio372async def test_cannot_aread_after_stream_consumed():373 stream = AsyncIteratorStream(aiterator=async_streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 374–377why, one step back374 response = httpx.Response(375 200,376 stream=stream,377 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 378–394why, one step back378379 content = b""380 async for part in response.aiter_bytes():381 content += part382383 with pytest.raises(httpx.StreamConsumed):384 await response.aread()385386387def test_cannot_read_after_response_closed():388 is_closed = False389390 def close_func():391 nonlocal is_closed392 is_closed = True393394 stream = IteratorStream(iterator=streaming_body(), close_func=close_func)Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 395–398why, one step back395 response = httpx.Response(396 200,397 stream=stream,398 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 399–417why, one step back399400 response.close()401 assert is_closed402403 with pytest.raises(httpx.ResponseClosed):404 response.read()405406407@pytest.mark.asyncio408async def test_cannot_aread_after_response_closed():409 is_closed = False410411 async def close_func():412 nonlocal is_closed413 is_closed = True414415 stream = AsyncIteratorStream(416 aiterator=async_streaming_body(), close_func=close_func417 )Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 418–421why, one step back418 response = httpx.Response(419 200,420 stream=stream,421 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 422–432why, one step back422423 await response.aclose()424 assert is_closed425426 with pytest.raises(httpx.ResponseClosed):427 await response.aread()428429430@pytest.mark.asyncio431async def test_elapsed_not_available_until_closed():432 stream = AsyncIteratorStream(aiterator=async_streaming_body())Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 433–436why, one step back433 response = httpx.Response(434 200,435 stream=stream,436 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 437–442why, one step back437438 with pytest.raises(RuntimeError):439 response.elapsed440441442def test_unknown_status_code():Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 443–445why, one step back443 response = httpx.Response(444 600,445 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 446–454why, one step back446 assert response.status_code == 600447 assert response.reason_phrase == ""448 assert response.text == ""449450451def test_json_with_specified_encoding():452 data = {"greeting": "hello", "recipient": "world"}453 content = json.dumps(data).encode("utf-16")454 headers = {"Content-Type": "application/json, charset=utf-16"}Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 455–459why, one step back455 response = httpx.Response(456 200,457 content=content,458 headers=headers,459 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 460–466why, one step back460 assert response.json() == data461462463def test_json_with_options():464 data = {"greeting": "hello", "recipient": "world", "amount": 1}465 content = json.dumps(data).encode("utf-16")466 headers = {"Content-Type": "application/json, charset=utf-16"}Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 467–471why, one step back467 response = httpx.Response(468 200,469 content=content,470 headers=headers,471 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 472–478why, one step back472 assert response.json(parse_int=str)["amount"] == "1"473474475def test_json_without_specified_encoding():476 data = {"greeting": "hello", "recipient": "world"}477 content = json.dumps(data).encode("utf-32-be")478 headers = {"Content-Type": "application/json"}Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 479–483why, one step back479 response = httpx.Response(480 200,481 content=content,482 headers=headers,483 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 484–493why, one step back484 assert response.json() == data485486487def test_json_without_specified_encoding_decode_error():488 data = {"greeting": "hello", "recipient": "world"}489 content = json.dumps(data).encode("utf-32-be")490 headers = {"Content-Type": "application/json"}491 # force incorrect guess from `guess_json_utf` to trigger error492 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):493 response = httpx.Response(Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 494–496why, one step back494 200,495 content=content,496 headers=headers,When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
line 497why, one step back497 )Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 498why, one step back498 with pytest.raises(json.decoder.JSONDecodeError):When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 499–501why, one step back499 response.json()500501Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 502–512why, one step back502def test_json_without_specified_encoding_value_error():503 data = {"greeting": "hello", "recipient": "world"}504 content = json.dumps(data).encode("utf-32-be")505 headers = {"Content-Type": "application/json"}506 # force incorrect guess from `guess_json_utf` to trigger error507 with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):508 response = httpx.Response(200, content=content, headers=headers)509 with pytest.raises(ValueError):510 response.json()511512When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
lines 513–529why, one step back513@pytest.mark.parametrize(514 "headers, expected",515 [516 (517 {"Link": "<https://example.com>; rel='preload'"},518 {"preload": {"rel": "preload", "url": "https://example.com"}},519 ),520 (521 {"Link": '</hub>; rel="hub", </resource>; rel="self"'},522 {523 "hub": {"url": "/hub", "rel": "hub"},524 "self": {"url": "/resource", "rel": "self"},525 },526 ),527 ],528)529def test_link_headers(headers, expected):Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 530–534why, one step back530 response = httpx.Response(531 200,532 content=None,533 headers=headers,534 )When setting headers, fallback to `utf-8` if no encoding is specified yet. (#820)Piotr Staroszczykbefore adoption50d337e
line 535why, one step back535 assert response.links == expectedMake the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 536–542why, one step back536537538@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))539def test_decode_error_with_request(header_value):540 headers = [(b"Content-Encoding", header_value)]541 body = b"test 123"542 compressed_body = brotli.compress(body)[3:]Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 543–549why, one step back543 with pytest.raises(ValueError):544 httpx.Response(545 200,546 headers=headers,547 content=compressed_body,548 )549Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 550why, one step back550 with pytest.raises(httpx.DecodingError):Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 551–556why, one step back551 httpx.Response(552 200,553 headers=headers,554 content=compressed_body,555 request=httpx.Request("GET", "https://www.example.org/"),556 )Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 557–579why, one step back557558559@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))560def test_value_error_without_request(header_value):561 headers = [(b"Content-Encoding", header_value)]562 body = b"test 123"563 compressed_body = brotli.compress(body)[3:]564 with pytest.raises(ValueError):565 httpx.Response(200, headers=headers, content=compressed_body)566567568def test_response_with_unset_request():569 response = httpx.Response(200, content=b"Hello, world!")570571 assert response.status_code == 200572 assert response.reason_phrase == "OK"573 assert response.text == "Hello, world!"574 assert not response.is_error575576577def test_set_request_after_init():578 response = httpx.Response(200, content=b"Hello, world!")579Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
line 580why, one step back580 response.request = httpx.Request("GET", "https://www.example.org")Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
line 581why, one step back581Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
lines 582–583why, one step back582 assert response.request.method == "GET"583 assert response.request.url == "https://www.example.org"Make the response's request parameter optional (#1238)tbascoulbefore adoptione0b4528
lines 584–589why, one step back584585586def test_cannot_access_unset_request():587 response = httpx.Response(200, content=b"Hello, world!")588589 with pytest.raises(RuntimeError):Drop Response(..., request=...) style in test cases. (#1243)Tom Christiebefore adoptionde502a4
line 590why, one step back590 response.request