(create_app_and_client)
| 33 | |
| 34 | @pytest.mark.run_loop |
| 35 | def test_middleware_handles_exception(create_app_and_client): |
| 36 | |
| 37 | @asyncio.coroutine |
| 38 | def handler(request): |
| 39 | raise RuntimeError('Error text') |
| 40 | |
| 41 | @asyncio.coroutine |
| 42 | def middleware_factory(app, handler): |
| 43 | |
| 44 | @asyncio.coroutine |
| 45 | def middleware(request): |
| 46 | with pytest.raises(RuntimeError) as ctx: |
| 47 | yield from handler(request) |
| 48 | return web.Response(status=501, |
| 49 | text=str(ctx.value) + '[MIDDLEWARE]') |
| 50 | |
| 51 | return middleware |
| 52 | |
| 53 | app, client = yield from create_app_and_client() |
| 54 | app.middlewares.append(middleware_factory) |
| 55 | app.router.add_route('GET', '/', handler) |
| 56 | resp = yield from client.get('/') |
| 57 | assert 501 == resp.status |
| 58 | txt = yield from resp.text() |
| 59 | assert 'Error text[MIDDLEWARE]' == txt |
| 60 | |
| 61 | |
| 62 | @pytest.mark.run_loop |
nothing calls this directly
no test coverage detected