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

Function test_middleware_chain

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

Source from the content-addressed store, hash-verified

61
62@pytest.mark.run_loop
63def 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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected