Code Duplication    Length = 26-26 lines in 2 locations

tests/test_protocol_for_ws.py 1 location

@@ 11-36 (lines=26) @@
8
from tests import utils
9
10
11
async def test_rpc_call_with_positional_parameters(aiohttp_client):
12
    """
13
    --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
14
    <-- {"jsonrpc": "2.0", "result": 19, "id": 1}
15
16
    --> {"jsonrpc": "2.0", "method": "subtract", "params": [23, 42], "id": 2}
17
    <-- {"jsonrpc": "2.0", "result": -19, "id": 2}
18
    """
19
20
    def subtract(a, b):
21
        return a - b
22
23
    rpc_server = aiohttp_rpc.WsJsonRpcServer()
24
    rpc_server.add_method(subtract)
25
26
    client = await utils.make_ws_client(aiohttp_client, rpc_server)
27
28
    async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc:
29
        assert await rpc.subtract(42, 23) == 19
30
        assert await rpc.subtract(23, 42) == -19
31
32
        result = await rpc.send_json({'jsonrpc': '2.0', 'method': 'subtract', 'params': [42, 23], 'id': 1})
33
        assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 1}
34
35
        result = await rpc.send_json({'jsonrpc': '2.0', 'method': 'subtract', 'params': [23, 42], 'id': 2})
36
        assert result[0] == {'jsonrpc': '2.0', 'result': -19, 'id': 2}
37
38
39
async def test_rpc_call_with_named_parameters(aiohttp_client):

tests/test_protocol_for_http.py 1 location

@@ 10-35 (lines=26) @@
7
from tests import utils
8
9
10
async def test_rpc_call_with_positional_parameters(aiohttp_client):
11
    """
12
    --> {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
13
    <-- {"jsonrpc": "2.0", "result": 19, "id": 1}
14
15
    --> {"jsonrpc": "2.0", "method": "subtract", "params": [23, 42], "id": 2}
16
    <-- {"jsonrpc": "2.0", "result": -19, "id": 2}
17
    """
18
19
    def subtract(a, b):
20
        return a - b
21
22
    rpc_server = aiohttp_rpc.JsonRpcServer()
23
    rpc_server.add_method(subtract)
24
25
    client = await utils.make_client(aiohttp_client, rpc_server)
26
27
    async with aiohttp_rpc.JsonRpcClient('/rpc', session=client) as rpc:
28
        assert await rpc.subtract(42, 23) == 19
29
        assert await rpc.subtract(23, 42) == -19
30
31
        result = await rpc.send_json({'jsonrpc': '2.0', 'method': 'subtract', 'params': [42, 23], 'id': 1})
32
        assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 1}
33
34
        result = await rpc.send_json({'jsonrpc': '2.0', 'method': 'subtract', 'params': [23, 42], 'id': 2})
35
        assert result[0] == {'jsonrpc': '2.0', 'result': -19, 'id': 2}
36
37
38
async def test_rpc_call_with_named_parameters(aiohttp_client):