Skip to content

make_mocked_request's default app should be a MagicMock #3134

@butla

Description

@butla

Long story short

App is, among other things, a container for objects with an application-wide use. The default right now is to populate the app in the Request returned by make_mocked_request with unittest.mock.Mock, which doesn't support indexing, thus crashing when values in the app are accessed, unless MagicMock (or a dictionary) is explicitly put as app in the the call to make_mocked_request. I think the default should be to create the app as a MagicMock.

I couldn't test if that would brake any tests, because running tox was just spewing missing .h file errors at me and wouldn't run anything.

Expected behaviour

>>> from aiohttp.test_utils import make_mocked_request
>>> r = make_mocked_request('GET', '/bla')
>>> r.app['some_value']
<MagicMock name='mock.__getitem__()' id='139715764977336'>

Actual behaviour

>>> from aiohttp.test_utils import make_mocked_request
>>> r = make_mocked_request('GET', '/bla')
>>> r.app['some_value']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Mock' object does not support item assignment
'Mock' object does not support item assignment

Your environment

Aiohttp server: 3.3.2
OS: Kubuntu 17.10 x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions