Debian Codegraph @

tests/test_request.py

raw
1 import pytest
2 import trio
3 from quart.wrappers.base import ClientDisconnectedError
4 from werkzeug.exceptions import RequestEntityTooLarge
5
6 from quart_trio.wrappers.request import TrioBody
7
8
9 @pytest.mark.trio
10 async def test_body_exceeds_max_content_length() -> None:
11 max_content_length = 5
12 body = TrioBody(None, max_content_length)
13 await body.put(b" " * (max_content_length + 1))
14 body.set_complete()
15 with pytest.raises(RequestEntityTooLarge):
16 await body
17
18
19 @pytest.mark.trio
20 async def test_body_streaming() -> None:
21 body = TrioBody(None, None)
22
23 async def produce() -> None:
24 await body.put(b"first")
25 await body.put(b"second")
26 body.set_complete()
27
28 async with trio.open_nursery() as nursery:
29 nursery.start_soon(produce)
30 data = b"".join([chunk async for chunk in body])
31 assert data == b"firstsecond"
32
33
34 @pytest.mark.trio
35 async def test_body_disconnect() -> None:
36 body = TrioBody(None, None)
37 body.disconnect()
38 with pytest.raises(ClientDisconnectedError):
39 await body.get()