moonraker-api 2.0.4__tar.gz → 2.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {moonraker-api-2.0.4/moonraker_api.egg-info → moonraker_api-2.0.6}/PKG-INFO +4 -6
  2. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/README.md +1 -1
  3. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/websockets/websocketclient.py +1 -1
  4. {moonraker-api-2.0.4 → moonraker_api-2.0.6/moonraker_api.egg-info}/PKG-INFO +4 -6
  5. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api.egg-info/SOURCES.txt +2 -1
  6. moonraker_api-2.0.6/setup.cfg +14 -0
  7. moonraker_api-2.0.6/tests/test_moonrakerclient.py +248 -0
  8. moonraker-api-2.0.4/setup.cfg +0 -7
  9. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/LICENSE.txt +0 -0
  10. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/MANIFEST.in +0 -0
  11. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/__init__.py +0 -0
  12. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/const.py +0 -0
  13. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/moonrakerclient.py +0 -0
  14. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/websockets/__init__.py +0 -0
  15. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/websockets/awaitabletask.py +0 -0
  16. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api/websockets/websocketdatahandler.py +0 -0
  17. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api.egg-info/dependency_links.txt +0 -0
  18. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api.egg-info/requires.txt +0 -0
  19. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/moonraker_api.egg-info/top_level.txt +0 -0
  20. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/requirements.txt +0 -0
  21. {moonraker-api-2.0.4 → moonraker_api-2.0.6}/setup.py +0 -0
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moonraker-api
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Async websocket API client for Moonraker
5
5
  Home-page: https://github.com/cmroche/moonraker-api
6
6
  Author: Clifford Roche
7
7
  Author-email:
8
- License: UNKNOWN
9
- Platform: UNKNOWN
10
8
  Classifier: Programming Language :: Python :: 3
11
9
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12
10
  Classifier: Operating System :: OS Independent
13
11
  Requires-Python: >=3.8
14
12
  Description-Content-Type: text/markdown
15
13
  License-File: LICENSE.txt
14
+ Requires-Dist: aiohttp~=3.8
15
+ Requires-Dist: async-timeout~=4.0
16
16
 
17
17
  ![Python package](https://github.com/cmroche/moonraker-api/workflows/Python%20package/badge.svg)
18
18
 
@@ -76,7 +76,7 @@ class APIConnector(MoonrakerListener):
76
76
  pass
77
77
  elif state == WEBSOCKET_STATE_READY:
78
78
  pass
79
- elif state == WEBSOCKET_STATE_PASSED:
79
+ elif state == WEBSOCKET_STATE_PAUSED:
80
80
  pass
81
81
  elif state == WEBSOCKET_STATE_STOPPED:
82
82
  pass
@@ -100,5 +100,3 @@ class APIConnector(MoonrakerListener):
100
100
 
101
101
  # Do stuff ...
102
102
  ```
103
-
104
-
@@ -60,7 +60,7 @@ class APIConnector(MoonrakerListener):
60
60
  pass
61
61
  elif state == WEBSOCKET_STATE_READY:
62
62
  pass
63
- elif state == WEBSOCKET_STATE_PASSED:
63
+ elif state == WEBSOCKET_STATE_PAUSED:
64
64
  pass
65
65
  elif state == WEBSOCKET_STATE_STOPPED:
66
66
  pass
@@ -306,7 +306,7 @@ class WebsocketClient:
306
306
 
307
307
  except ClientResponseError as error:
308
308
  _LOGGER.warning("Websocket request error: %s", error)
309
- if error.code == 401:
309
+ if error.status == 401:
310
310
  _LOGGER.error("API access is unauthorized")
311
311
  self.state = WEBSOCKET_STATE_STOPPING
312
312
  await set_exception(ClientNotAuthenticatedError)
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: moonraker-api
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Async websocket API client for Moonraker
5
5
  Home-page: https://github.com/cmroche/moonraker-api
6
6
  Author: Clifford Roche
7
7
  Author-email:
8
- License: UNKNOWN
9
- Platform: UNKNOWN
10
8
  Classifier: Programming Language :: Python :: 3
11
9
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12
10
  Classifier: Operating System :: OS Independent
13
11
  Requires-Python: >=3.8
14
12
  Description-Content-Type: text/markdown
15
13
  License-File: LICENSE.txt
14
+ Requires-Dist: aiohttp~=3.8
15
+ Requires-Dist: async-timeout~=4.0
16
16
 
17
17
  ![Python package](https://github.com/cmroche/moonraker-api/workflows/Python%20package/badge.svg)
18
18
 
@@ -76,7 +76,7 @@ class APIConnector(MoonrakerListener):
76
76
  pass
77
77
  elif state == WEBSOCKET_STATE_READY:
78
78
  pass
79
- elif state == WEBSOCKET_STATE_PASSED:
79
+ elif state == WEBSOCKET_STATE_PAUSED:
80
80
  pass
81
81
  elif state == WEBSOCKET_STATE_STOPPED:
82
82
  pass
@@ -100,5 +100,3 @@ class APIConnector(MoonrakerListener):
100
100
 
101
101
  # Do stuff ...
102
102
  ```
103
-
104
-
@@ -15,4 +15,5 @@ moonraker_api.egg-info/top_level.txt
15
15
  moonraker_api/websockets/__init__.py
16
16
  moonraker_api/websockets/awaitabletask.py
17
17
  moonraker_api/websockets/websocketclient.py
18
- moonraker_api/websockets/websocketdatahandler.py
18
+ moonraker_api/websockets/websocketdatahandler.py
19
+ tests/test_moonrakerclient.py
@@ -0,0 +1,14 @@
1
+ [tool:pytest]
2
+ asyncio_mode = auto
3
+ minversion = 6.0
4
+ addopts = -ra -q
5
+ testpaths =
6
+ tests
7
+
8
+ [metadata]
9
+ version = 2.0.6
10
+
11
+ [egg_info]
12
+ tag_build =
13
+ tag_date = 0
14
+
@@ -0,0 +1,248 @@
1
+ # Moonraker API Client
2
+ #
3
+ # Copyright (C) 2021 Clifford Roche <clifford.roche@gmail.com>
4
+ #
5
+ # This file may be distributed under the terms of the GNU GPLv3 license
6
+
7
+ """Moonraker client API tests."""
8
+
9
+ import asyncio
10
+ from unittest.mock import patch
11
+
12
+ import pytest
13
+ from aiohttp import web
14
+ from aiohttp.client_exceptions import ClientConnectionError
15
+
16
+ from moonraker_api.const import (
17
+ WEBSOCKET_STATE_CONNECTED,
18
+ WEBSOCKET_STATE_STOPPED,
19
+ WEBSOCKET_STATE_STOPPING,
20
+ )
21
+ from moonraker_api.websockets.websocketclient import (
22
+ ClientAlreadyConnectedError,
23
+ ClientNotAuthenticatedError,
24
+ ClientNotConnectedError,
25
+ )
26
+
27
+ from .common import (
28
+ create_moonraker_service,
29
+ create_moonraker_service_error,
30
+ create_moonraker_service_looping,
31
+ )
32
+ from .data import (
33
+ TEST_DATA_OBJECTS_QUERY,
34
+ TEST_DATA_SIMPLE_RESPONSE,
35
+ TEST_DATA_SUPPORTED_MODULES,
36
+ )
37
+
38
+
39
+ async def test_connect(aiohttp_server, moonraker):
40
+ """Test connecting to the websocket server"""
41
+ await create_moonraker_service_looping(aiohttp_server)
42
+
43
+ await moonraker.connect()
44
+
45
+ assert moonraker.is_connected
46
+ assert moonraker.state == WEBSOCKET_STATE_CONNECTED
47
+
48
+ await moonraker.disconnect()
49
+
50
+ assert not moonraker.is_connected
51
+ assert moonraker.state in [WEBSOCKET_STATE_STOPPED, WEBSOCKET_STATE_STOPPING]
52
+
53
+ assert moonraker.listener is not None
54
+ assert moonraker.listener.state_changed.call_count == 4
55
+ assert moonraker.listener.state_changed.call_args_list[0].args == ("ws_connecting",)
56
+ assert moonraker.listener.state_changed.call_args_list[1].args == ("ws_connected",)
57
+ assert moonraker.listener.state_changed.call_args_list[2].args == ("ws_stopping",)
58
+ assert moonraker.listener.state_changed.call_args_list[3].args == ("ws_stopped",)
59
+
60
+
61
+ async def test_connect_twice(aiohttp_server, moonraker):
62
+ """Test sending a request and waiting on a response"""
63
+ await create_moonraker_service_looping(aiohttp_server)
64
+
65
+ await moonraker.connect()
66
+ with pytest.raises(ClientAlreadyConnectedError):
67
+ await moonraker.connect()
68
+ assert moonraker.is_connected
69
+ assert moonraker.state == WEBSOCKET_STATE_CONNECTED
70
+
71
+ await moonraker.disconnect()
72
+ assert moonraker.state == WEBSOCKET_STATE_STOPPED
73
+
74
+
75
+ async def test_connect_unauthorized(aiohttp_server, moonraker):
76
+ """Test sending a request without authentication"""
77
+ await create_moonraker_service_error(aiohttp_server, web.HTTPUnauthorized())
78
+
79
+ with pytest.raises(ClientNotAuthenticatedError):
80
+ connected = await moonraker.connect()
81
+ assert not connected
82
+ assert not moonraker.is_connected
83
+ assert moonraker.state == WEBSOCKET_STATE_STOPPING
84
+
85
+ await moonraker.disconnect()
86
+ assert not moonraker.is_connected
87
+ assert moonraker.state == WEBSOCKET_STATE_STOPPED
88
+
89
+
90
+ async def test_api_request(aiohttp_server, moonraker):
91
+ """Test sending a request and waiting on a response"""
92
+ await create_moonraker_service_looping(aiohttp_server)
93
+
94
+ await moonraker.connect()
95
+ await moonraker.get_host_info()
96
+ await moonraker.disconnect()
97
+
98
+
99
+ async def test_api_request_disconnect(aiohttp_server, moonraker):
100
+ """Test server hangup after request"""
101
+ await create_moonraker_service_looping(aiohttp_server, disconnect=True)
102
+
103
+ await moonraker.connect()
104
+ with pytest.raises(asyncio.CancelledError):
105
+ await moonraker.get_host_info()
106
+ await moonraker.disconnect()
107
+
108
+
109
+ async def test_api_request_timeout(aiohttp_server, moonraker):
110
+ """Test server hangup after request"""
111
+ await create_moonraker_service_looping(aiohttp_server, no_response=True)
112
+
113
+ await moonraker.connect()
114
+ with pytest.raises(asyncio.TimeoutError):
115
+ await moonraker.get_host_info()
116
+ await moonraker.disconnect()
117
+
118
+
119
+ async def test_api_request_not_connected(aiohttp_server, moonraker):
120
+ """Test sending a request before we are connected to the server"""
121
+ await create_moonraker_service_looping(aiohttp_server)
122
+
123
+ with pytest.raises(ClientNotConnectedError):
124
+ await moonraker.get_host_info()
125
+ await moonraker.disconnect()
126
+
127
+ assert not moonraker.is_connected
128
+ assert moonraker.state == WEBSOCKET_STATE_STOPPED
129
+ assert moonraker.listener is not None
130
+ assert moonraker.listener.state_changed.call_count == 0
131
+
132
+
133
+ @pytest.mark.skip(reason="Not possible to test yet")
134
+ async def test_api_send_error(aiohttp_server, moonraker):
135
+ """Test handling error while sending requests"""
136
+ await create_moonraker_service(aiohttp_server)
137
+
138
+ with pytest.raises(ClientConnectionError):
139
+ await moonraker.get_host_info()
140
+ await moonraker.disconnect()
141
+
142
+ assert not moonraker.is_connected
143
+ assert moonraker.state == WEBSOCKET_STATE_STOPPED
144
+
145
+
146
+ @pytest.mark.skip(reason="Not possible to test yet")
147
+ async def test_api_recv_error(aiohttp_server, moonraker):
148
+ """Test handling error while receiving requests"""
149
+ await create_moonraker_service(aiohttp_server)
150
+
151
+ with patch("AwaitableTask.get_result"):
152
+ with pytest.raises(ClientConnectionError):
153
+ await moonraker.get_host_info()
154
+ await moonraker.disconnect()
155
+
156
+ assert not moonraker.is_connected
157
+ assert moonraker.state == WEBSOCKET_STATE_STOPPED
158
+
159
+
160
+ async def test_support_modules(aiohttp_server, moonraker):
161
+ """Test getting the supported modules from the API"""
162
+ await create_moonraker_service_looping(aiohttp_server)
163
+
164
+ await moonraker.connect()
165
+ supported_modules = await moonraker.get_supported_modules()
166
+ await moonraker.disconnect()
167
+
168
+ assert supported_modules == TEST_DATA_SUPPORTED_MODULES["result"]["objects"]
169
+
170
+
171
+ async def test_service_status(aiohttp_server, moonraker):
172
+ """Test getting the supported modules from the API"""
173
+ await create_moonraker_service_looping(aiohttp_server)
174
+
175
+ await moonraker.connect()
176
+ status = await moonraker.get_klipper_status()
177
+ await moonraker.disconnect()
178
+
179
+ assert status == "ready"
180
+
181
+
182
+ @pytest.mark.parametrize(
183
+ "method",
184
+ [
185
+ "printer.restart",
186
+ "printer.emergency_stop",
187
+ "printer.firmware_restart",
188
+ ],
189
+ )
190
+ async def test_simple_rpc_apis(aiohttp_server, moonraker, method):
191
+ """Test RPC method calls"""
192
+ await create_moonraker_service_looping(aiohttp_server)
193
+
194
+ await moonraker.connect()
195
+ assert moonraker.is_connected
196
+ response = await moonraker.call_method(method)
197
+ await moonraker.disconnect()
198
+ assert not moonraker.is_connected
199
+
200
+ assert response is not None
201
+ assert response == TEST_DATA_SIMPLE_RESPONSE["result"]
202
+
203
+
204
+ @pytest.mark.parametrize(
205
+ "method, args",
206
+ [
207
+ (
208
+ "printer.objects.query",
209
+ {"objects": {"gcode_move": None, "toolhead": ["position", "status"]}},
210
+ )
211
+ ],
212
+ )
213
+ async def test_args_rpc_api(aiohttp_server, moonraker, method, args):
214
+ """Test RPC call with argument passing."""
215
+ await create_moonraker_service_looping(aiohttp_server)
216
+
217
+ await moonraker.connect()
218
+ assert moonraker.is_connected
219
+ response = await moonraker.call_method(method, **args)
220
+
221
+ assert response is not None
222
+ assert response == TEST_DATA_OBJECTS_QUERY["result"]
223
+
224
+ await moonraker.disconnect()
225
+ assert not moonraker.is_connected
226
+
227
+
228
+ @pytest.mark.skip(reason="Not implemented yet")
229
+ @pytest.mark.parametrize(
230
+ "method",
231
+ ["testing.send_gcode_response"],
232
+ )
233
+ async def test_subscribe_rpc_api(aiohttp_server, moonraker, method):
234
+ """Test RPC call with argument passing."""
235
+ await create_moonraker_service_looping(aiohttp_server)
236
+
237
+ await moonraker.connect()
238
+ assert moonraker.is_connected
239
+ response = await moonraker.call_method(method)
240
+
241
+ # Subscribe to updates
242
+ assert response is not None
243
+ assert response == TEST_DATA_SIMPLE_RESPONSE["result"]
244
+
245
+ # Check that responses are received
246
+
247
+ await moonraker.disconnect()
248
+ assert not moonraker.is_connected
@@ -1,7 +0,0 @@
1
- [metadata]
2
- version = 2.0.4
3
-
4
- [egg_info]
5
- tag_build =
6
- tag_date = 0
7
-
File without changes
File without changes
File without changes