| Total Complexity | 2 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import os |
||
| 2 | import sys |
||
| 3 | |||
| 4 | import pytest |
||
| 5 | |||
| 6 | import aiohttp_rpc |
||
| 7 | |||
| 8 | |||
| 9 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
||
| 10 | from tests import utils |
||
| 11 | |||
| 12 | |||
| 13 | @pytest.mark.asyncio |
||
| 14 | async def test_middleware(aiohttp_client): |
||
| 15 | def method(): |
||
| 16 | return 'ok' |
||
| 17 | |||
| 18 | async def test_middleware(request, handler): |
||
| 19 | request.method = 'method' |
||
| 20 | response = await handler(request) |
||
| 21 | response.result += '!' |
||
| 22 | return response |
||
| 23 | |||
| 24 | rpc_server = aiohttp_rpc.JsonRpcServer(middlewares=(test_middleware,)) |
||
| 25 | rpc_server.add_method(method) |
||
| 26 | |||
| 27 | client = await utils.make_client(aiohttp_client, rpc_server) |
||
| 28 | |||
| 29 | async with aiohttp_rpc.JsonRpcClient('/rpc', session=client) as rpc: |
||
| 30 | assert await rpc.call('my_method') == 'ok!' |
||
| 31 |