(create_app_and_client)
| 5 | |
| 6 | @pytest.mark.run_loop |
| 7 | def test_middleware_modifies_response(create_app_and_client): |
| 8 | |
| 9 | @asyncio.coroutine |
| 10 | def handler(request): |
| 11 | return web.Response(body=b'OK') |
| 12 | |
| 13 | @asyncio.coroutine |
| 14 | def middleware_factory(app, handler): |
| 15 | |
| 16 | @asyncio.coroutine |
| 17 | def middleware(request): |
| 18 | resp = yield from handler(request) |
| 19 | assert 200 == resp.status |
| 20 | resp.set_status(201) |
| 21 | resp.text = resp.text + '[MIDDLEWARE]' |
| 22 | return resp |
| 23 | return middleware |
| 24 | |
| 25 | app, client = yield from create_app_and_client() |
| 26 | app.middlewares.append(middleware_factory) |
| 27 | app.router.add_route('GET', '/', handler) |
| 28 | resp = yield from client.get('/') |
| 29 | assert 201 == resp.status |
| 30 | txt = yield from resp.text() |
| 31 | assert 'OK[MIDDLEWARE]' == txt |
| 32 | |
| 33 | |
| 34 | @pytest.mark.run_loop |
nothing calls this directly
no test coverage detected