Passed
Push — master ( 9909db...135e2c )
by Michael
03:54
created

tests.test_websocket.test_args()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
cc 2
nop 1
1
import aiohttp_rpc
2
from tests import utils
3
4
5
async def test_args(aiohttp_client):
6
    def method(a=1):
7
        return [1, 2, a]
8
9
    rpc_server = aiohttp_rpc.WsJsonRpcServer()
10
    rpc_server.add_method(method)
11
12
    client = await utils.make_ws_client(aiohttp_client, rpc_server)
13
14
    async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc:
15
        assert await rpc.call('method') == [1, 2, 1]
16
        assert await rpc.call('method', 1) == [1, 2, 1]
17
18
19
async def test_batch(aiohttp_client):
20
    def method_1(a=1):
21
        return [1, a]
22
23
    def method_2():
24
        return 1
25
26
    rpc_server = aiohttp_rpc.WsJsonRpcServer()
27
    rpc_server.add_methods((method_1, method_2,))
28
29
    client = await utils.make_ws_client(aiohttp_client, rpc_server)
30
31
    async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc:
32
        assert await rpc.batch(('method_1', 'method_2',)) == [[1, 1], 1]
33
        assert await rpc.batch((('method_1', 4), ('method_1', [], {'a': 5},),)) == [[1, 4], [1, 5]]
34
35
    async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc:
36
        assert await rpc.batch_notify(('method_1', 'method_2',)) is None
37
        assert await rpc.batch_notify((('method_1', 4), ('method_1', [], {'a': 5},),)) is None
38