Skip to content

Commit

Permalink
make_mocked_request: default app can store values
Browse files Browse the repository at this point in the history
  • Loading branch information
butla committed Aug 20, 2018
1 parent 99914c8 commit 765c4eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions tests/test_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand Down

0 comments on commit 765c4eb

Please sign in to comment.