(create_app_and_client)
| 61 | |
| 62 | @pytest.mark.run_loop |
| 63 | def test_middleware_chain(create_app_and_client): |
| 64 | |
| 65 | @asyncio.coroutine |
| 66 | def handler(request): |
| 67 | return web.Response(text='OK') |
| 68 | |
| 69 | def make_factory(num): |
| 70 | |
| 71 | @asyncio.coroutine |
| 72 | def factory(app, handler): |
| 73 | |
| 74 | def middleware(request): |
| 75 | resp = yield from handler(request) |
| 76 | resp.text = resp.text + '[{}]'.format(num) |
| 77 | return resp |
| 78 | |
| 79 | return middleware |
| 80 | return factory |
| 81 | |
| 82 | app, client = yield from create_app_and_client() |
| 83 | app.middlewares.append(make_factory(1)) |
| 84 | app.middlewares.append(make_factory(2)) |
| 85 | app.router.add_route('GET', '/', handler) |
| 86 | resp = yield from client.get('/') |
| 87 | assert 200 == resp.status |
| 88 | txt = yield from resp.text() |
| 89 | assert 'OK[2][1]' == txt |
nothing calls this directly
no test coverage detected