test_content.py
This file
Path
tests/test_content.py
483 lines · 16.0 KiB · Python
Last changed by
Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
History of this fileTake it
The walk stopped after 200 commits: lines older than ecbece1 point at it.
:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 1–7why, one step back1import io2import typing34import pytest56import httpx7Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 8–9why, one step back8method = "POST"9url = "https://www.example.com":pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 10why, one step back10Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 11why, one step back11:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 12–13why, one step back12@pytest.mark.asyncio13async def test_empty_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 14–16why, one step back14 request = httpx.Request(method, url)15 assert isinstance(request.stream, httpx.SyncByteStream)16 assert isinstance(request.stream, httpx.AsyncByteStream):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 17why, one step back17Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 18–19why, one step back18 sync_content = b"".join([part for part in request.stream])19 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 20why, one step back20Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 21why, one step back21 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 22–27why, one step back22 assert sync_content == b""23 assert async_content == b""242526@pytest.mark.asyncio27async def test_bytes_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 28–30why, one step back28 request = httpx.Request(method, url, content=b"Hello, world!")29 assert isinstance(request.stream, typing.Iterable)30 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 31why, one step back31Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 32–33why, one step back32 sync_content = b"".join([part for part in request.stream])33 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 34why, one step back34Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 35why, one step back35 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 36–40why, one step back36 assert sync_content == b"Hello, world!"37 assert async_content == b"Hello, world!"3839 # Support 'data' for compat with requests.40 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 41–43why, one step back41 request = httpx.Request(method, url, data=b"Hello, world!") # type: ignore42 assert isinstance(request.stream, typing.Iterable)43 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 44why, one step back44Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 45–46why, one step back45 sync_content = b"".join([part for part in request.stream])46 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 47why, one step back47Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 48why, one step back48 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 49–54why, one step back49 assert sync_content == b"Hello, world!"50 assert async_content == b"Hello, world!"515253@pytest.mark.asyncio54async def test_bytesio_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 55–57why, one step back55 request = httpx.Request(method, url, content=io.BytesIO(b"Hello, world!"))56 assert isinstance(request.stream, typing.Iterable)57 assert not isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 58why, one step back58Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 59why, one step back59 content = b"".join([part for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 60why, one step back60Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 61why, one step back61 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 62–65why, one step back62 assert content == b"Hello, world!"636465@pytest.mark.asyncioRead upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
lines 66–67why, one step back66async def test_async_bytesio_content():67 class AsyncBytesIO:Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 68why, one step back68 def __init__(self, content: bytes) -> None:Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
lines 69–71why, one step back69 self._idx = 070 self._content = content71Typing: enable disallow_incomplete_defs (#2476)Martijn Pietersbefore adoption049afe5
line 72why, one step back72 async def aread(self, chunk_size: int) -> bytes:Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
lines 73–77why, one step back73 chunk = self._content[self._idx : self._idx + chunk_size]74 self._idx = self._idx + chunk_size75 return chunk7677 async def __aiter__(self):use # pragma: no cover instead of # pragma: nocover (#2471)Adrian Garcia Badaraccobefore adoption16e2830
line 78why, one step back78 yield self._content # pragma: no coverRead upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
line 79why, one step back79Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 80–82why, one step back80 request = httpx.Request(method, url, content=AsyncBytesIO(b"Hello, world!"))81 assert not isinstance(request.stream, typing.Iterable)82 assert isinstance(request.stream, typing.AsyncIterable)Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
line 83why, one step back83Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 84why, one step back84 content = b"".join([part async for part in request.stream])Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
line 85why, one step back85Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 86–89why, one step back86 assert request.headers == {87 "Host": "www.example.com",88 "Transfer-Encoding": "chunked",89 }Read upload files using `read(CHUNK_SIZE)` rather than `iter()`. (#1948)Tom Christiebefore adoption6f5865f
lines 90–93why, one step back90 assert content == b"Hello, world!"919293@pytest.mark.asyncio:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 94why, one step back94async def test_iterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 95why, one step back95 def hello_world() -> typing.Iterator[bytes]::pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 96–98why, one step back96 yield b"Hello, "97 yield b"world!"98Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 99–101why, one step back99 request = httpx.Request(method, url, content=hello_world())100 assert isinstance(request.stream, typing.Iterable)101 assert not isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 102why, one step back102Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 103why, one step back103 content = b"".join([part for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 104why, one step back104Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 105–108why, one step back105 assert request.headers == {106 "Host": "www.example.com",107 "Transfer-Encoding": "chunked",108 }:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 109–111why, one step back109 assert content == b"Hello, world!"110111 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 112why, one step back112 [part for part in request.stream]:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 113–115why, one step back113114 # Support 'data' for compat with requests.115 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 116–118why, one step back116 request = httpx.Request(method, url, data=hello_world()) # type: ignore117 assert isinstance(request.stream, typing.Iterable)118 assert not isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 119why, one step back119Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 120why, one step back120 content = b"".join([part for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 121why, one step back121Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 122–125why, one step back122 assert request.headers == {123 "Host": "www.example.com",124 "Transfer-Encoding": "chunked",125 }:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 126–130why, one step back126 assert content == b"Hello, world!"127128129@pytest.mark.asyncio130async def test_aiterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 131why, one step back131 async def hello_world() -> typing.AsyncIterator[bytes]::pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 132–134why, one step back132 yield b"Hello, "133 yield b"world!"134Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 135–137why, one step back135 request = httpx.Request(method, url, content=hello_world())136 assert not isinstance(request.stream, typing.Iterable)137 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 138why, one step back138Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 139why, one step back139 content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 140why, one step back140Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 141–144why, one step back141 assert request.headers == {142 "Host": "www.example.com",143 "Transfer-Encoding": "chunked",144 }:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 145–147why, one step back145 assert content == b"Hello, world!"146147 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 148why, one step back148 [part async for part in request.stream]:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 149–151why, one step back149150 # Support 'data' for compat with requests.151 with pytest.warns(DeprecationWarning):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 152–154why, one step back152 request = httpx.Request(method, url, data=hello_world()) # type: ignore153 assert not isinstance(request.stream, typing.Iterable)154 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 155why, one step back155Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 156why, one step back156 content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 157why, one step back157Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 158–161why, one step back158 assert request.headers == {159 "Host": "www.example.com",160 "Transfer-Encoding": "chunked",161 }:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 162–166why, one step back162 assert content == b"Hello, world!"163164165@pytest.mark.asyncio166async def test_json_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 167–169why, one step back167 request = httpx.Request(method, url, json={"Hello": "world!"})168 assert isinstance(request.stream, typing.Iterable)169 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 170why, one step back170Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 171–172why, one step back171 sync_content = b"".join([part for part in request.stream])172 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 173why, one step back173Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 174–175why, one step back174 assert request.headers == {175 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 176–184why, one step back176 "Content-Length": "19",177 "Content-Type": "application/json",178 }179 assert sync_content == b'{"Hello": "world!"}'180 assert async_content == b'{"Hello": "world!"}'181182183@pytest.mark.asyncio184async def test_urlencoded_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 185–187why, one step back185 request = httpx.Request(method, url, data={"Hello": "world!"})186 assert isinstance(request.stream, typing.Iterable)187 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 188why, one step back188Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 189–190why, one step back189 sync_content = b"".join([part for part in request.stream])190 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 191why, one step back191Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 192–193why, one step back192 assert request.headers == {193 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 194–202why, one step back194 "Content-Length": "14",195 "Content-Type": "application/x-www-form-urlencoded",196 }197 assert sync_content == b"Hello=world%21"198 assert async_content == b"Hello=world%21"199200201@pytest.mark.asyncio202async def test_urlencoded_boolean():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 203–205why, one step back203 request = httpx.Request(method, url, data={"example": True})204 assert isinstance(request.stream, typing.Iterable)205 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 206why, one step back206Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 207–208why, one step back207 sync_content = b"".join([part for part in request.stream])208 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 209why, one step back209Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 210–211why, one step back210 assert request.headers == {211 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 212–220why, one step back212 "Content-Length": "12",213 "Content-Type": "application/x-www-form-urlencoded",214 }215 assert sync_content == b"example=true"216 assert async_content == b"example=true"217218219@pytest.mark.asyncio220async def test_urlencoded_none():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 221–223why, one step back221 request = httpx.Request(method, url, data={"example": None})222 assert isinstance(request.stream, typing.Iterable)223 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 224why, one step back224Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 225–226why, one step back225 sync_content = b"".join([part for part in request.stream])226 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 227why, one step back227Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 228–229why, one step back228 assert request.headers == {229 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 230–238why, one step back230 "Content-Length": "8",231 "Content-Type": "application/x-www-form-urlencoded",232 }233 assert sync_content == b"example="234 assert async_content == b"example="235236237@pytest.mark.asyncio238async def test_urlencoded_list():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 239–241why, one step back239 request = httpx.Request(method, url, data={"example": ["a", 1, True]})240 assert isinstance(request.stream, typing.Iterable)241 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 242why, one step back242Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 243–244why, one step back243 sync_content = b"".join([part for part in request.stream])244 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 245why, one step back245Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 246–247why, one step back246 assert request.headers == {247 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 248–257why, one step back248 "Content-Length": "32",249 "Content-Type": "application/x-www-form-urlencoded",250 }251 assert sync_content == b"example=a&example=1&example=true"252 assert async_content == b"example=a&example=1&example=true"253254255@pytest.mark.asyncio256async def test_multipart_files_content():257 files = {"file": io.BytesIO(b"<file content>")}Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 258–266why, one step back258 headers = {"Content-Type": "multipart/form-data; boundary=+++"}259 request = httpx.Request(260 method,261 url,262 files=files,263 headers=headers,264 )265 assert isinstance(request.stream, typing.Iterable)266 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 267why, one step back267Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 268–269why, one step back268 sync_content = b"".join([part for part in request.stream])269 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 270why, one step back270Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 271–272why, one step back271 assert request.headers == {272 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 273–301why, one step back273 "Content-Length": "138",274 "Content-Type": "multipart/form-data; boundary=+++",275 }276 assert sync_content == b"".join(277 [278 b"--+++\r\n",279 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',280 b"Content-Type: application/octet-stream\r\n",281 b"\r\n",282 b"<file content>\r\n",283 b"--+++--\r\n",284 ]285 )286 assert async_content == b"".join(287 [288 b"--+++\r\n",289 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',290 b"Content-Type: application/octet-stream\r\n",291 b"\r\n",292 b"<file content>\r\n",293 b"--+++--\r\n",294 ]295 )296297298@pytest.mark.asyncio299async def test_multipart_data_and_files_content():300 data = {"message": "Hello, world!"}301 files = {"file": io.BytesIO(b"<file content>")}Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 302–305why, one step back302 headers = {"Content-Type": "multipart/form-data; boundary=+++"}303 request = httpx.Request(method, url, data=data, files=files, headers=headers)304 assert isinstance(request.stream, typing.Iterable)305 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 306why, one step back306Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 307–308why, one step back307 sync_content = b"".join([part for part in request.stream])308 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 309why, one step back309Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 310–311why, one step back310 assert request.headers == {311 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 312–346why, one step back312 "Content-Length": "210",313 "Content-Type": "multipart/form-data; boundary=+++",314 }315 assert sync_content == b"".join(316 [317 b"--+++\r\n",318 b'Content-Disposition: form-data; name="message"\r\n',319 b"\r\n",320 b"Hello, world!\r\n",321 b"--+++\r\n",322 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',323 b"Content-Type: application/octet-stream\r\n",324 b"\r\n",325 b"<file content>\r\n",326 b"--+++--\r\n",327 ]328 )329 assert async_content == b"".join(330 [331 b"--+++\r\n",332 b'Content-Disposition: form-data; name="message"\r\n',333 b"\r\n",334 b"Hello, world!\r\n",335 b"--+++\r\n",336 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',337 b"Content-Type: application/octet-stream\r\n",338 b"\r\n",339 b"<file content>\r\n",340 b"--+++--\r\n",341 ]342 )343344345@pytest.mark.asyncio346async def test_empty_request():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 347–349why, one step back347 request = httpx.Request(method, url, data={}, files={})348 assert isinstance(request.stream, typing.Iterable)349 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 350why, one step back350Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 351–352why, one step back351 sync_content = b"".join([part for part in request.stream])352 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 353why, one step back353Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 354why, one step back354 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 355–360why, one step back355 assert sync_content == b""356 assert async_content == b""357358359def test_invalid_argument():360 with pytest.raises(TypeError):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 361why, one step back361 httpx.Request(method, url, content=123) # type: ignore:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 362–369why, one step back362363364@pytest.mark.asyncio365async def test_multipart_multiple_files_single_input_content():366 files = [367 ("file", io.BytesIO(b"<file content 1>")),368 ("file", io.BytesIO(b"<file content 2>")),369 ]Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 370–373why, one step back370 headers = {"Content-Type": "multipart/form-data; boundary=+++"}371 request = httpx.Request(method, url, files=files, headers=headers)372 assert isinstance(request.stream, typing.Iterable)373 assert isinstance(request.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 374why, one step back374Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 375–376why, one step back375 sync_content = b"".join([part for part in request.stream])376 async_content = b"".join([part async for part in request.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 377why, one step back377Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 378–379why, one step back378 assert request.headers == {379 "Host": "www.example.com",:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 380–416why, one step back380 "Content-Length": "271",381 "Content-Type": "multipart/form-data; boundary=+++",382 }383 assert sync_content == b"".join(384 [385 b"--+++\r\n",386 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',387 b"Content-Type: application/octet-stream\r\n",388 b"\r\n",389 b"<file content 1>\r\n",390 b"--+++\r\n",391 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',392 b"Content-Type: application/octet-stream\r\n",393 b"\r\n",394 b"<file content 2>\r\n",395 b"--+++--\r\n",396 ]397 )398 assert async_content == b"".join(399 [400 b"--+++\r\n",401 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',402 b"Content-Type: application/octet-stream\r\n",403 b"\r\n",404 b"<file content 1>\r\n",405 b"--+++\r\n",406 b'Content-Disposition: form-data; name="file"; filename="upload"\r\n',407 b"Content-Type: application/octet-stream\r\n",408 b"\r\n",409 b"<file content 2>\r\n",410 b"--+++--\r\n",411 ]412 )413414415@pytest.mark.asyncio416async def test_response_empty_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 417–419why, one step back417 response = httpx.Response(200)418 assert isinstance(response.stream, typing.Iterable)419 assert isinstance(response.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 420why, one step back420Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 421–422why, one step back421 sync_content = b"".join([part for part in response.stream])422 async_content = b"".join([part async for part in response.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 423why, one step back423Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 424why, one step back424 assert response.headers == {}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 425–430why, one step back425 assert sync_content == b""426 assert async_content == b""427428429@pytest.mark.asyncio430async def test_response_bytes_content():Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 431–433why, one step back431 response = httpx.Response(200, content=b"Hello, world!")432 assert isinstance(response.stream, typing.Iterable)433 assert isinstance(response.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 434why, one step back434Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 435–436why, one step back435 sync_content = b"".join([part for part in response.stream])436 async_content = b"".join([part async for part in response.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 437why, one step back437Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 438why, one step back438 assert response.headers == {"Content-Length": "13"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 439–444why, one step back439 assert sync_content == b"Hello, world!"440 assert async_content == b"Hello, world!"441442443@pytest.mark.asyncio444async def test_response_iterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 445why, one step back445 def hello_world() -> typing.Iterator[bytes]::pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 446–448why, one step back446 yield b"Hello, "447 yield b"world!"448Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 449–451why, one step back449 response = httpx.Response(200, content=hello_world())450 assert isinstance(response.stream, typing.Iterable)451 assert not isinstance(response.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 452why, one step back452Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 453why, one step back453 content = b"".join([part for part in response.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 454why, one step back454Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 455why, one step back455 assert response.headers == {"Transfer-Encoding": "chunked"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 456–458why, one step back456 assert content == b"Hello, world!"457458 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 459why, one step back459 [part for part in response.stream]:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 460–463why, one step back460461462@pytest.mark.asyncio463async def test_response_aiterator_content():Typing: enable disallow_untyped_calls (#2479)Martijn Pietersbefore adoption933551c
line 464why, one step back464 async def hello_world() -> typing.AsyncIterator[bytes]::pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 465–467why, one step back465 yield b"Hello, "466 yield b"world!"467Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
lines 468–470why, one step back468 response = httpx.Response(200, content=hello_world())469 assert not isinstance(response.stream, typing.Iterable)470 assert isinstance(response.stream, typing.AsyncIterable):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 471why, one step back471Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 472why, one step back472 content = b"".join([part async for part in response.stream]):pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
line 473why, one step back473Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 474why, one step back474 assert response.headers == {"Transfer-Encoding": "chunked"}:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 475–477why, one step back475 assert content == b"Hello, world!"476477 with pytest.raises(httpx.StreamConsumed):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 478why, one step back478 [part async for part in response.stream]:pencil: Docs patch following PR #1791 section compatibility.encoding (#1812)TAHRI Ahmed Rbefore adoptionecbece1
lines 479–482why, one step back479480481def test_response_invalid_argument():482 with pytest.raises(TypeError):Use httpx public API for 'test_content' tests (#2494)Tom Christiebefore adoption71a1589
line 483why, one step back483 httpx.Response(200, content=123) # type: ignore