| @@ 39-68 (lines=30) @@ | ||
| 36 | assert result[0] == {'jsonrpc': '2.0', 'result': -19, 'id': 2} |
|
| 37 | ||
| 38 | ||
| 39 | async def test_rpc_call_with_named_parameters(aiohttp_client): |
|
| 40 | """ |
|
| 41 | --> {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3} |
|
| 42 | <-- {"jsonrpc": "2.0", "result": 19, "id": 3} |
|
| 43 | ||
| 44 | --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} |
|
| 45 | <-- {"jsonrpc": "2.0", "result": 19, "id": 4} |
|
| 46 | """ |
|
| 47 | ||
| 48 | def subtract(*, subtrahend, minuend): |
|
| 49 | return minuend - subtrahend |
|
| 50 | ||
| 51 | rpc_server = aiohttp_rpc.WsJsonRpcServer() |
|
| 52 | rpc_server.add_method(subtract) |
|
| 53 | ||
| 54 | client = await utils.make_ws_client(aiohttp_client, rpc_server) |
|
| 55 | ||
| 56 | async with aiohttp_rpc.WsJsonRpcClient('/rpc', session=client) as rpc: |
|
| 57 | assert await rpc.subtract(subtrahend=23, minuend=42) == 19 |
|
| 58 | assert await rpc.subtract(minuend=42, subtrahend=23) == 19 |
|
| 59 | ||
| 60 | result = await rpc.send_json({ |
|
| 61 | 'jsonrpc': '2.0', 'method': 'subtract', 'params': {"subtrahend": 23, "minuend": 42}, 'id': 3, |
|
| 62 | }) |
|
| 63 | assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 3} |
|
| 64 | ||
| 65 | result = await rpc.send_json({ |
|
| 66 | 'jsonrpc': '2.0', 'method': 'subtract', 'params': {"minuend": 42, "subtrahend": 23}, 'id': 4 |
|
| 67 | }) |
|
| 68 | assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 4} |
|
| 69 | ||
| 70 | ||
| 71 | async def test_notification(aiohttp_client): |
|
| @@ 38-67 (lines=30) @@ | ||
| 35 | assert result[0] == {'jsonrpc': '2.0', 'result': -19, 'id': 2} |
|
| 36 | ||
| 37 | ||
| 38 | async def test_rpc_call_with_named_parameters(aiohttp_client): |
|
| 39 | """ |
|
| 40 | --> {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3} |
|
| 41 | <-- {"jsonrpc": "2.0", "result": 19, "id": 3} |
|
| 42 | ||
| 43 | --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} |
|
| 44 | <-- {"jsonrpc": "2.0", "result": 19, "id": 4} |
|
| 45 | """ |
|
| 46 | ||
| 47 | def subtract(*, subtrahend, minuend): |
|
| 48 | return minuend - subtrahend |
|
| 49 | ||
| 50 | rpc_server = aiohttp_rpc.JsonRpcServer() |
|
| 51 | rpc_server.add_method(subtract) |
|
| 52 | ||
| 53 | client = await utils.make_client(aiohttp_client, rpc_server) |
|
| 54 | ||
| 55 | async with aiohttp_rpc.JsonRpcClient('/rpc', session=client) as rpc: |
|
| 56 | assert await rpc.subtract(subtrahend=23, minuend=42) == 19 |
|
| 57 | assert await rpc.subtract(minuend=42, subtrahend=23) == 19 |
|
| 58 | ||
| 59 | result = await rpc.send_json({ |
|
| 60 | 'jsonrpc': '2.0', 'method': 'subtract', 'params': {"subtrahend": 23, "minuend": 42}, 'id': 3, |
|
| 61 | }) |
|
| 62 | assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 3} |
|
| 63 | ||
| 64 | result = await rpc.send_json({ |
|
| 65 | 'jsonrpc': '2.0', 'method': 'subtract', 'params': {"minuend": 42, "subtrahend": 23}, 'id': 4 |
|
| 66 | }) |
|
| 67 | assert result[0] == {'jsonrpc': '2.0', 'result': 19, 'id': 4} |
|
| 68 | ||
| 69 | ||
| 70 | async def test_notification(aiohttp_client): |
|