Passed
Push — master ( 55adfd...84b7e9 )
by Michael
03:30
created

test_middleware.test_middleware()   A

Complexity

Conditions 2

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 18
rs 9.7
c 0
b 0
f 0
cc 2
nop 1
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