diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index fdc63ee9c4d..ea7b858c725 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -448,7 +448,17 @@ def teardown_test_loop(loop, fast=False): def _create_app_mock(): - app = mock.Mock() + def get_dict(app, key): + return app.__app_dict[key] + + def set_dict(app, key, value): + app.__app_dict[key] = value + + app = mock.MagicMock() + app.__app_dict = {} + app.__getitem__ = get_dict + app.__setitem__ = set_dict + app._debug = False app.on_response_prepare = Signal(app) app.on_response_prepare.freeze() diff --git a/tests/test_test_utils.py b/tests/test_test_utils.py index a45e7cab753..1d45aad7cbf 100644 --- a/tests/test_test_utils.py +++ b/tests/test_test_utils.py @@ -189,6 +189,12 @@ def test_make_mocked_request_app(): assert req.app is app +def test_make_mocked_request_app_can_store_values(): + req = make_mocked_request('GET', '/') + req.app['a_field'] = 'a_value' + assert req.app['a_field'] == 'a_value' + + 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'}