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
(cherry picked from commit 8a525d9)
  • Loading branch information
rahulnht authored and patchback[bot] committed Sep 1, 2024
1 parent 6881e0d commit ea8dab8
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 @@ -274,6 +274,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 @@ -31,6 +31,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 @@ -631,7 +632,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 @@ -700,9 +701,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 @@ -239,6 +239,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 ea8dab8

Please sign in to comment.