Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds unit tests for the MQTT client, authentication, and API client modules, along with introducing Python fallback implementations for Rust-based map and utility functions to support testing environments without the Rust extension.
- Added comprehensive unit tests for
MqttClientwithout Docker dependencies - Added extensive unit tests for authentication flows including error handling and retry logic
- Added unit tests for API client device retrieval and product IoT map functionality
- Introduced Python stub implementations in
deebot_client/rs/module for map data structures and utility functions
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_mqtt_client_unit.py | New unit tests for MQTT client configuration and lifecycle without Docker |
| tests/test_authentication.py | Added unit tests for authenticator credential expiry, post operations, and _AuthClient login flows |
| tests/test_api_client.py | New unit tests for API client device retrieval and product IoT map operations |
| deebot_client/rs/util.py | New Python fallback utility functions for MD5 hashing and data decompression |
| deebot_client/rs/map.py | New Python stub classes for map data structures (BackgroundImage, TracePoints, MapInfo, MapData, enums) |
| deebot_client/rs/init.py | New module initialization file |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async def dummy_task() -> None: | ||
| await asyncio.sleep(10) | ||
|
|
||
| import asyncio |
There was a problem hiding this comment.
The asyncio module is imported after it's used. Move the import to the top of the file with other imports at line 3.
| async def dummy_task() -> None: | ||
| pass | ||
|
|
||
| import asyncio |
There was a problem hiding this comment.
The asyncio module is imported after it's used. Move the import to the top of the file with other imports at line 3.
| def set(self, baset64_data: str) -> None: | ||
| """Set map info (base64-compressed JSON).""" | ||
| self._data = baset64_data |
There was a problem hiding this comment.
Corrected spelling of 'baset64_data' to 'base64_data'.
| def set(self, baset64_data: str) -> None: | |
| """Set map info (base64-compressed JSON).""" | |
| self._data = baset64_data | |
| def set(self, base64_data: str) -> None: | |
| """Set map info (base64-compressed JSON).""" | |
| self._data = base64_data |
| def decompress_7z_base64_data(data: str) -> str: | ||
| """Decompress 7z base64 encoded data.""" | ||
| import base64 | ||
| import gzip | ||
| try: | ||
| decoded = base64.b64decode(data) | ||
| return gzip.decompress(decoded).decode("utf-8") | ||
| except Exception: | ||
| return "" | ||
|
|
||
|
|
||
| def decompress_base64_data(data: str) -> str: | ||
| """Decompress base64 encoded data.""" | ||
| import base64 | ||
| import gzip | ||
| try: | ||
| decoded = base64.b64decode(data) | ||
| return gzip.decompress(decoded).decode("utf-8") | ||
| except Exception: | ||
| return "" |
There was a problem hiding this comment.
The functions decompress_7z_base64_data and decompress_base64_data have identical implementations. This code duplication should be eliminated by either removing one function or having one delegate to the other if they're meant to serve different purposes.
| rest_config = create_rest_config( | ||
| session=session, | ||
| device_id="test_device", | ||
| alpha_2_country="IT", | ||
| ) |
There was a problem hiding this comment.
Variable rest_config is not used.
| rest_config = create_rest_config( | |
| session=session, | |
| device_id="test_device", | |
| alpha_2_country="IT", | |
| ) |
| from unittest.mock import AsyncMock, patch | ||
|
|
There was a problem hiding this comment.
Import of 'AsyncMock' is not used.
Import of 'patch' is not used.
| from unittest.mock import AsyncMock, patch |
| from deebot_client.api_client import ApiClient, Devices | ||
| from deebot_client.const import ( | ||
| PATH_API_APPSVR_APP, | ||
| PATH_API_PIM_PRODUCT_IOT_MAP, |
There was a problem hiding this comment.
Import of 'PATH_API_PIM_PRODUCT_IOT_MAP' is not used.
| PATH_API_PIM_PRODUCT_IOT_MAP, |
| from deebot_client.mqtt_client import MqttClient, create_mqtt_config | ||
|
|
||
| if TYPE_CHECKING: | ||
| from deebot_client.authentication import RestConfiguration |
There was a problem hiding this comment.
Import of 'RestConfiguration' is not used.
| from deebot_client.authentication import RestConfiguration |
…qtt_client - Add test_api_client.py with 100% coverage for API client operations - Test device retrieval for different device types (eco-ng, eco-legacy, unsupported) - Test error handling and edge cases - Test product IoT map retrieval - Expand test_authentication.py from 45% to 89% coverage - Add tests for _AuthClient login flow including success and error paths - Test invalid credentials and authentication errors - Test post method with timeout and retry logic - Test login token retry mechanism - Test China country-specific login paths - Add test_mqtt_client_unit.py with tests for MQTT client configuration - Test MQTT config creation with various URL schemes - Test SSL context handling - Test connection and disconnection logic - Test task cancellation - Add Python mock implementations for Rust modules (deebot_client/rs/) to enable tests to run without needing to build Rust components Overall test coverage improved from 90% to 93%
0caab3f to
1f25b7c
Compare
- Remove unused imports and variables - Move imports to top of file - Fix quote consistency (use double quotes) - Add noqa comments for test-specific warnings - Fix blank lines after docstrings - Consolidate nested with statements All ruff checks now pass.
…qtt_client
Add test_api_client.py with 100% coverage for API client operations
Expand test_authentication.py from 45% to 89% coverage
Add test_mqtt_client_unit.py with tests for MQTT client configuration
Add Python mock implementations for Rust modules (deebot_client/rs/) to enable tests to run without needing to build Rust components
Overall test coverage improved from 90% to 93%