Skip to content

Commit

Permalink
Fix test_utils.make_mocked_request behaviour for empty payload (#7168)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulnht authored Sep 1, 2024
1 parent 51fade1 commit 8a525d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
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

0 comments on commit 8a525d9

Please sign in to comment.