| @@ 28-50 (lines=23) @@ | ||
| 25 | assert await rpc.call('method', 1) == [1, 2, 1] |
|
| 26 | ||
| 27 | ||
| 28 | @pytest.mark.asyncio |
|
| 29 | async def test_batch(aiohttp_client): |
|
| 30 | def method_1(a=1): |
|
| 31 | return [1, 2, a] |
|
| 32 | ||
| 33 | def method_2(): |
|
| 34 | return [1] |
|
| 35 | ||
| 36 | rpc_server = aiohttp_rpc.WsJsonRpcServer() |
|
| 37 | rpc_server.add_methods(( |
|
| 38 | method_1, |
|
| 39 | method_2, |
|
| 40 | )) |
|
| 41 | ||
| 42 | client = await utils.make_ws_client(aiohttp_client, rpc_server) |
|
| 43 | ||
| 44 | async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc: |
|
| 45 | assert await rpc.batch(('method_1', 'method_2',)) == [[1, 2, 1], [1]] |
|
| 46 | assert await rpc.batch((('method_1', 4), ('method_1', [], {'a': 5}),)) == [[1, 2, 4], [1, 2, 5]] |
|
| 47 | ||
| 48 | async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc: |
|
| 49 | assert await rpc.batch_notify(('method_1', 'method_2',)) is None |
|
| 50 | assert await rpc.batch_notify((('method_1', 4), ('method_1', [], {'a': 5}),)) is None |
|
| 51 | ||
| @@ 13-34 (lines=22) @@ | ||
| 10 | from tests import utils |
|
| 11 | ||
| 12 | ||
| 13 | @pytest.mark.asyncio |
|
| 14 | async def test_batch(aiohttp_client): |
|
| 15 | def method_1(a=1): |
|
| 16 | return [1, 2, a] |
|
| 17 | ||
| 18 | def method_2(): |
|
| 19 | return [1] |
|
| 20 | ||
| 21 | rpc_server = aiohttp_rpc.JsonRpcServer() |
|
| 22 | rpc_server.add_methods(( |
|
| 23 | method_1, |
|
| 24 | method_2, |
|
| 25 | )) |
|
| 26 | ||
| 27 | assert await rpc_server.call('method_1') == [1, 2, 1] |
|
| 28 | assert await rpc_server.call('method_2') == [1] |
|
| 29 | ||
| 30 | client = await utils.make_client(aiohttp_client, rpc_server) |
|
| 31 | ||
| 32 | async with aiohttp_rpc.JsonRpcClient('/rpc', session=client) as rpc: |
|
| 33 | assert await rpc.batch(('method_1', 'method_2',)) == [[1, 2, 1], [1]] |
|
| 34 | assert await rpc.batch((('method_1', 4), ('method_1', [], {'a': 5}),)) == [[1, 2, 4], [1, 2, 5]] |
|
| 35 | ||
| 36 | ||
| 37 | @pytest.mark.asyncio |
|