Skip to content

Commit

Permalink
add failing test showing invalid request.app in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
popravich committed Nov 23, 2017
1 parent e180b12 commit 9a2f7bb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9a2f7bb

Please sign in to comment.