|
2 | 2 |
|
3 | 3 | from galaxy.api.plugin import Plugin |
4 | 4 | from galaxy.api.consts import Platform |
5 | | -from galaxy.api.jsonrpc import InvalidParams |
| 5 | +from galaxy.api.jsonrpc import Connection, InvalidParams, Request |
6 | 6 | from galaxy.unittest.mock import delayed_return_value_iterable |
7 | 7 |
|
8 | 8 | from tests import create_message, get_messages |
@@ -101,33 +101,30 @@ async def test_tick_after_handshake(plugin, read): |
101 | 101 |
|
102 | 102 |
|
103 | 103 | @pytest.mark.asyncio |
104 | | -async def test_notification_invalid_params_does_not_crash(plugin, read, write): |
105 | | - request = { |
106 | | - "jsonrpc": "2.0", |
107 | | - "method": "install_game", |
108 | | - "params": {} |
109 | | - } |
110 | | - read.side_effect = [create_message(request), b""] |
| 104 | +async def test_notification_invalid_params_does_not_crash(plugin, read, write, reader, writer): |
| 105 | + called = False |
111 | 106 |
|
112 | | - await plugin.run() |
113 | | - await plugin.wait_closed() |
| 107 | + def callback(game_id): |
| 108 | + nonlocal called |
| 109 | + called = True |
| 110 | + |
| 111 | + connection = Connection(reader, writer) |
| 112 | + connection.register_notification("install_game", callback, immediate=True) |
| 113 | + connection._handle_notification(Request(method="install_game", params={}, id=None)) |
114 | 114 |
|
115 | | - plugin.install_game.assert_not_called() |
| 115 | + assert called is False |
116 | 116 | assert get_messages(write) == [] |
117 | 117 |
|
118 | 118 |
|
119 | 119 | @pytest.mark.asyncio |
120 | | -async def test_request_invalid_params_returns_error(plugin, read, write): |
121 | | - request = { |
122 | | - "jsonrpc": "2.0", |
123 | | - "id": "8", |
124 | | - "method": "start_achievements_import", |
125 | | - "params": {} |
126 | | - } |
127 | | - read.side_effect = [create_message(request), b""] |
128 | | - |
129 | | - await plugin.run() |
130 | | - await plugin.wait_closed() |
| 120 | +async def test_request_invalid_params_returns_error(plugin, read, write, reader, writer): |
| 121 | + async def callback(game_ids): |
| 122 | + return game_ids |
| 123 | + |
| 124 | + connection = Connection(reader, writer) |
| 125 | + connection.register_method("start_achievements_import", callback, immediate=False) |
| 126 | + connection._handle_request(Request(method="start_achievements_import", params={}, id="8")) |
| 127 | + await connection.wait_closed() |
131 | 128 |
|
132 | 129 | assert get_messages(write) == [ |
133 | 130 | { |
|
0 commit comments