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

Function test_middleware_modifies_response

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

Source from the content-addressed store, hash-verified

5
6@pytest.mark.run_loop
7def 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

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