MCPcopy
hub / github.com/aio-libs/aiohttp / test_middleware_handles_exception

Function test_middleware_handles_exception

tests/test_web_middleware.py:35–59  ·  view source on GitHub ↗
(create_app_and_client)

Source from the content-addressed store, hash-verified

33
34@pytest.mark.run_loop
35def 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

Callers

nothing calls this directly

Calls 5

create_app_and_clientFunction · 0.85
appendMethod · 0.80
add_routeMethod · 0.45
getMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected