Add test coverage for global authentication mode#163
Conversation
- Created mock response files for global API endpoints - Added SmartGlobalMockRouter for global auth testing - Implemented comprehensive tests for _init_vehicles_global() and _update_global_vehicle_details() - All tests passing, no regression in existing tests Co-authored-by: DasBasti <1713093+DasBasti@users.noreply.github.com>
- Move json import to module level in common.py - Fix SmartMockRouter.add_global_routes to use side_effect handler - Rename prepare_global_account_with_vehicles to create_global_account_with_vehicles Co-authored-by: DasBasti <1713093+DasBasti@users.noreply.github.com>
- Remove trailing whitespace from blank lines - Apply ruff formatting Co-authored-by: DasBasti <1713093+DasBasti@users.noreply.github.com>
- Extract vehicle_details_handler to module-level _create_vehicle_details_handler function - Create shared _add_global_vehicle_routes helper function - Both SmartMockRouter and SmartGlobalMockRouter now use shared implementation Co-authored-by: DasBasti <1713093+DasBasti@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for the global authentication mode, which was previously untested. The implementation includes new test cases, mock infrastructure, and fixture data for the global API endpoints.
Changes:
- Added test coverage for
_init_vehicles_global()and_update_global_vehicle_details()functions - Introduced
SmartGlobalMockRouterto handle global API endpoint mocking - Created mock JSON responses for global vehicle list, details, and abilities APIs
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pysmarthashtag/tests/test_global_auth.py |
New test file with 5 comprehensive tests covering global authentication flow, vehicle initialization, details update, endpoint URL configuration, and auth mode detection |
pysmarthashtag/tests/common.py |
Added SmartGlobalMockRouter class and helper functions (_create_vehicle_details_handler, _add_global_vehicle_routes) to support global API mocking |
pysmarthashtag/tests/replys/global_vehicle_list.json |
Mock response for vehicle ownership list endpoint with 2 test vehicles |
pysmarthashtag/tests/replys/global_vehicle_details.json |
Mock response for vehicle details endpoint for TestVIN0000000001 |
pysmarthashtag/tests/replys/global_vehicle_details2.json |
Mock response for vehicle details endpoint for TestVIN0000000002 |
pysmarthashtag/tests/replys/global_vehicle_abilities.json |
Mock response for vehicle abilities endpoint with comprehensive capability data |
| await account.login() | ||
|
|
||
| # Verify that the account uses global HMAC authentication | ||
| from pysmarthashtag.const import SmartAuthMode |
There was a problem hiding this comment.
Import statements should be placed at the module level rather than inside functions. Move this import to the top of the file with the other imports from pysmarthashtag.const. This follows PEP 8 guidelines and improves code readability and maintainability.
| @pytest.mark.asyncio | ||
| async def test_global_with_endpoint_urls(smart_global_fixture: respx.Router): | ||
| """Test global authentication using EndpointUrls directly.""" | ||
| from pysmarthashtag.const import EndpointUrls |
There was a problem hiding this comment.
Import statements should be placed at the module level rather than inside functions. Move this import to the top of the file with the other imports from pysmarthashtag.const. This follows PEP 8 guidelines and improves code readability and maintainability.
The global authentication flow (
_init_vehicles_global()and_update_global_vehicle_details()) lacked test coverage.Changes
Test Infrastructure (
common.py)SmartGlobalMockRouterwith routes for global API endpoints:/iam/service/api/v1/login(HMAC authentication)/vc/vehicle/v1/ownership/list(vehicle list)/vc/vehicle/v1/vehicleCustomerInfo(vehicle details)/vc/vehicle/v1/ability/{modelCode}/{vin}(capabilities)Test Coverage (
test_global_auth.py)test_init_vehicles_global- Validates vehicle parsing from global APItest_update_global_vehicle_details- Verifiescombine_dataandabilitiespopulationtest_global_login- Tests HMAC authentication flowtest_global_with_endpoint_urls- Tests directEndpointUrlsconfigurationtest_global_auth_mode_detection- Confirms auth mode detectionMock Responses
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.