|
9 | 9 | from freezegun.api import FrozenDateTimeFactory |
10 | 10 | import pytest |
11 | 11 | from syrupy.assertion import SnapshotAssertion |
| 12 | +from tesla_fleet_api.const import Scope, VehicleDataEndpoint |
12 | 13 | from tesla_fleet_api.exceptions import ( |
13 | 14 | InvalidRegion, |
14 | 15 | InvalidToken, |
|
36 | 37 | from homeassistant.helpers import device_registry as dr |
37 | 38 |
|
38 | 39 | from . import setup_platform |
| 40 | +from .conftest import create_config_entry |
39 | 41 | from .const import VEHICLE_ASLEEP, VEHICLE_DATA_ALT |
40 | 42 |
|
41 | 43 | from tests.common import MockConfigEntry, async_fire_time_changed |
@@ -497,3 +499,65 @@ async def test_bad_implementation( |
497 | 499 | assert result["type"] is FlowResultType.FORM |
498 | 500 | assert result["step_id"] == "reauth_confirm" |
499 | 501 | assert not result["errors"] |
| 502 | + |
| 503 | + |
| 504 | +async def test_vehicle_without_location_scope( |
| 505 | + hass: HomeAssistant, |
| 506 | + expires_at: int, |
| 507 | + mock_vehicle_data: AsyncMock, |
| 508 | +) -> None: |
| 509 | + """Test vehicle setup without VEHICLE_LOCATION scope excludes location endpoint.""" |
| 510 | + |
| 511 | + # Create config entry without VEHICLE_LOCATION scope |
| 512 | + config_entry = create_config_entry( |
| 513 | + expires_at, |
| 514 | + [ |
| 515 | + Scope.OPENID, |
| 516 | + Scope.OFFLINE_ACCESS, |
| 517 | + Scope.VEHICLE_DEVICE_DATA, |
| 518 | + # Deliberately exclude Scope.VEHICLE_LOCATION |
| 519 | + ], |
| 520 | + ) |
| 521 | + |
| 522 | + await setup_platform(hass, config_entry) |
| 523 | + assert config_entry.state is ConfigEntryState.LOADED |
| 524 | + |
| 525 | + # Verify that vehicle_data was called without LOCATION_DATA endpoint |
| 526 | + mock_vehicle_data.assert_called() |
| 527 | + call_args = mock_vehicle_data.call_args |
| 528 | + endpoints = call_args.kwargs.get("endpoints", []) |
| 529 | + |
| 530 | + # Should not include LOCATION_DATA endpoint |
| 531 | + assert VehicleDataEndpoint.LOCATION_DATA not in endpoints |
| 532 | + |
| 533 | + # Should include other endpoints |
| 534 | + assert VehicleDataEndpoint.CHARGE_STATE in endpoints |
| 535 | + assert VehicleDataEndpoint.CLIMATE_STATE in endpoints |
| 536 | + assert VehicleDataEndpoint.DRIVE_STATE in endpoints |
| 537 | + assert VehicleDataEndpoint.VEHICLE_STATE in endpoints |
| 538 | + assert VehicleDataEndpoint.VEHICLE_CONFIG in endpoints |
| 539 | + |
| 540 | + |
| 541 | +async def test_vehicle_with_location_scope( |
| 542 | + hass: HomeAssistant, |
| 543 | + normal_config_entry: MockConfigEntry, |
| 544 | + mock_vehicle_data: AsyncMock, |
| 545 | +) -> None: |
| 546 | + """Test vehicle setup with VEHICLE_LOCATION scope includes location endpoint.""" |
| 547 | + await setup_platform(hass, normal_config_entry) |
| 548 | + assert normal_config_entry.state is ConfigEntryState.LOADED |
| 549 | + |
| 550 | + # Verify that vehicle_data was called with LOCATION_DATA endpoint |
| 551 | + mock_vehicle_data.assert_called() |
| 552 | + call_args = mock_vehicle_data.call_args |
| 553 | + endpoints = call_args.kwargs.get("endpoints", []) |
| 554 | + |
| 555 | + # Should include LOCATION_DATA endpoint when scope is present |
| 556 | + assert VehicleDataEndpoint.LOCATION_DATA in endpoints |
| 557 | + |
| 558 | + # Should include all other endpoints |
| 559 | + assert VehicleDataEndpoint.CHARGE_STATE in endpoints |
| 560 | + assert VehicleDataEndpoint.CLIMATE_STATE in endpoints |
| 561 | + assert VehicleDataEndpoint.DRIVE_STATE in endpoints |
| 562 | + assert VehicleDataEndpoint.VEHICLE_STATE in endpoints |
| 563 | + assert VehicleDataEndpoint.VEHICLE_CONFIG in endpoints |
0 commit comments