From 908684c4a62e173f077295451f93cedfa09732d6 Mon Sep 17 00:00:00 2001 From: Michal Bultrowicz Date: Sun, 5 Aug 2018 20:01:31 +0200 Subject: [PATCH] make_mocked_request: subscriptable default app --- aiohttp/test_utils.py | 2 +- tests/test_test_utils.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index fdc63ee9c4d..daa8527e11d 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -448,7 +448,7 @@ def teardown_test_loop(loop, fast=False): def _create_app_mock(): - app = mock.Mock() + app = mock.MagicMock() 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..92d4d7a978c 100644 --- a/tests/test_test_utils.py +++ b/tests/test_test_utils.py @@ -189,6 +189,11 @@ def test_make_mocked_request_app(): assert req.app is app +def test_make_mocked_request_app_doesnt_crash_on_key_access(): + req = make_mocked_request('GET', '/') + req.app["accessing this shouldn't crash"] + + 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'}