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

Propagate match_info in make_mocked_request #2331

Merged
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
4 changes: 3 additions & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def get_extra_info(key):


def make_mocked_request(method, path, headers=None, *,
match_info=sentinel,
version=HttpVersion(1, 1), closing=False,
app=None,
writer=sentinel,
Expand Down Expand Up @@ -564,7 +565,8 @@ def timeout(*args, **kw):
protocol, payload_writer, task, loop,
client_max_size=client_max_size)

match_info = UrlMappingMatchInfo({}, mock.Mock())
match_info = UrlMappingMatchInfo(
{} if match_info is sentinel else match_info, mock.Mock())
match_info.add_app(app)
req._match_info = match_info

Expand Down
6 changes: 6 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ conditions that hard to reproduce on real server::
version=HttpVersion(1, 1), \
closing=False, \
app=None, \
match_info=sentinel, \
reader=sentinel, \
writer=sentinel, \
transport=sentinel, \
Expand All @@ -391,6 +392,9 @@ conditions that hard to reproduce on real server::
by the multidict.CIMultiDict constructor.
:type headers: dict, multidict.CIMultiDict, list of pairs

:param match_info: mapping containing the info to match with url parameters.
:type match_info: dict

:param version: namedtuple with encoded HTTP version
:type version: aiohttp.protocol.HttpVersion

Expand Down Expand Up @@ -418,6 +422,8 @@ conditions that hard to reproduce on real server::

:return: :class:`aiohttp.web.Request` object.

.. versionadded:: 2.3
*match_info* parameter.

.. _aiohttp-testing-writing-testable-services:

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 @@ -255,6 +255,11 @@ def test_make_mocked_request_app():
assert req.app is app


def test_make_mocked_request_match_info():
req = make_mocked_request('GET', '/', match_info={'a': '1', 'b': '2'})
assert req.match_info == {'a': '1', 'b': '2'}


def test_make_mocked_request_content():
payload = mock.Mock()
req = make_mocked_request('GET', '/', payload=payload)
Expand Down