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

test_middleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 21
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_middleware() 0 18 2
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