Add body_exists to MockRequest in aiohttp util (#100932)
* Add body_exists to MockRequest in aiohttp util * Add body_exists to MockRequest in aiohttp util * Add body_exists to MockRequest in aiohttp util
This commit is contained in:
parent
785b46af22
commit
59207be5f8
2 changed files with 13 additions and 1 deletions
|
@ -66,6 +66,11 @@ class MockRequest:
|
|||
"""Return the body as text."""
|
||||
return MockStreamReader(self._content)
|
||||
|
||||
@property
|
||||
def body_exists(self) -> bool:
|
||||
"""Return True if request has HTTP BODY, False otherwise."""
|
||||
return bool(self._text)
|
||||
|
||||
async def json(self, loads: JSONDecoder = json_loads) -> Any:
|
||||
"""Return the body as JSON."""
|
||||
return loads(self._text)
|
||||
|
|
|
@ -12,12 +12,19 @@ async def test_request_json() -> None:
|
|||
|
||||
|
||||
async def test_request_text() -> None:
|
||||
"""Test a JSON request."""
|
||||
"""Test bytes in request."""
|
||||
request = aiohttp.MockRequest(b"hello", status=201, mock_source="test")
|
||||
assert request.body_exists
|
||||
assert request.status == 201
|
||||
assert await request.text() == "hello"
|
||||
|
||||
|
||||
async def test_request_body_exists() -> None:
|
||||
"""Test body exists."""
|
||||
request = aiohttp.MockRequest(b"", mock_source="test")
|
||||
assert not request.body_exists
|
||||
|
||||
|
||||
async def test_request_post_query() -> None:
|
||||
"""Test a JSON request."""
|
||||
request = aiohttp.MockRequest(
|
||||
|
|
Loading…
Add table
Reference in a new issue