Skip to content

Add test coverage for global authentication mode#163

Merged
DasBasti merged 6 commits into
retry-international-authfrom
copilot/sub-pr-161
Feb 4, 2026
Merged

Add test coverage for global authentication mode#163
DasBasti merged 6 commits into
retry-international-authfrom
copilot/sub-pr-161

Conversation

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

The global authentication flow (_init_vehicles_global() and _update_global_vehicle_details()) lacked test coverage.

Changes

Test Infrastructure (common.py)

  • Added SmartGlobalMockRouter with 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)
  • Implemented VIN-specific response handling via side effects
  • Extracted shared helpers to eliminate duplication between mock routers

Test Coverage (test_global_auth.py)

  • test_init_vehicles_global - Validates vehicle parsing from global API
  • test_update_global_vehicle_details - Verifies combine_data and abilities population
  • test_global_login - Tests HMAC authentication flow
  • test_global_with_endpoint_urls - Tests direct EndpointUrls configuration
  • test_global_auth_mode_detection - Confirms auth mode detection

Mock Responses

  • Added JSON fixtures for global API responses (vehicle list, details, abilities)
# Tests now cover global region usage
endpoint_urls = get_endpoint_urls_for_region(SmartRegion.GLOBAL)
account = SmartAccount(username, password, endpoint_urls=endpoint_urls)
await account.get_vehicles()

assert account._is_global_auth()
assert len(account.vehicles) == 2
assert "abilities" in account.vehicles["VIN123"].data

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 4, 2026 21:26
- 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>
Copilot AI changed the title [WIP] Update global authentication mode implementation Add test coverage for global authentication mode Feb 4, 2026
Copilot AI requested a review from DasBasti February 4, 2026 21:33
@DasBasti DasBasti marked this pull request as ready for review February 4, 2026 21:43
Copilot AI review requested due to automatic review settings February 4, 2026 21:43
@DasBasti DasBasti merged commit b3df57a into retry-international-auth Feb 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SmartGlobalMockRouter to 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

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@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

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants