From 9a2f7bb5ecca2eae4fd76702c03121e44fa3a7b2 Mon Sep 17 00:00:00 2001 From: Alexey Popravka Date: Thu, 23 Nov 2017 17:35:20 +0200 Subject: [PATCH] add failing test showing invalid request.app in middleware --- tests/test_web_functional.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_web_functional.py b/tests/test_web_functional.py index e05c7b34bd7..bd705ee45f2 100644 --- a/tests/test_web_functional.py +++ b/tests/test_web_functional.py @@ -1290,6 +1290,35 @@ async def on_signal(app): assert [app, subapp1, subapp2] == order +async def test_subapp_middleware_context(loop, test_client): + values = [] + + def show_app_context(appname): + @web.middleware + async def middleware(request, handler): + values.append('{} see {}'.format(appname, request.app['my_value'])) + return await handler(request) + return middleware + + async def handler(request): + return web.Response(text='Ok') + + app = web.Application() + app['my_value'] = 'root' + app.middlewares.append(show_app_context('app')) + subapp = web.Application() + subapp['my_value'] = 'sub' + subapp.middlewares.append(show_app_context('subapp')) + subapp.router.add_get('/', handler) + app.add_subapp('/sub/', subapp) + + client = await test_client(app) + resp = await client.get('/sub/') + assert 200 == resp.status + assert 'Ok' == await resp.text() + assert ['app see root', 'subapp see sub'] == values + + async def test_custom_date_header(loop, test_client): async def handler(request):