Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_utils.make_mocked_request behaviour for empty payload #7168

Merged
merged 8 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/7167.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed ``make_mocked_request()`` to use empty payload by default -- by :user:`rahulnht`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Philipp A.
Pieter van Beek
Qiao Han
Rafael Viotti
Rahul Nahata
Raphael Bialon
Raúl Cumplido
Required Field
Expand Down
6 changes: 2 additions & 4 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from .client_ws import ClientWebSocketResponse
from .helpers import sentinel
from .http import HttpVersion, RawRequestMessage
from .streams import EMPTY_PAYLOAD, StreamReader
from .typedefs import StrOrURL
from .web import (
Application,
Expand Down Expand Up @@ -594,7 +595,7 @@ def make_mocked_request(
writer: Any = sentinel,
protocol: Any = sentinel,
transport: Any = sentinel,
payload: Any = sentinel,
payload: StreamReader = EMPTY_PAYLOAD,
sslcontext: Optional[SSLContext] = None,
client_max_size: int = 1024**2,
loop: Any = ...,
Expand Down Expand Up @@ -663,9 +664,6 @@ def make_mocked_request(
protocol.transport = transport
protocol.writer = writer

if payload is sentinel:
payload = mock.Mock()

req = Request(
message, payload, protocol, writer, task, loop, client_max_size=client_max_size
)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def test_make_mocked_request_content() -> None:
assert req.content is payload


async def test_make_mocked_request_empty_payload() -> None:
req = make_mocked_request("GET", "/")
assert await req.read() == b""


def test_make_mocked_request_transport() -> None:
transport = mock.Mock()
req = make_mocked_request("GET", "/", transport=transport)
Expand Down
Loading