Improve code quality of Tesla Fleet tests (#123959)

This commit is contained in:
Brett Adams 2024-08-15 17:59:08 +10:00 committed by GitHub
parent ac30efb5ac
commit dde1ecbf5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 34 additions and 28 deletions

View file

@ -106,7 +106,7 @@ def mock_wake_up() -> Generator[AsyncMock]:
@pytest.fixture(autouse=True)
def mock_live_status() -> Generator[AsyncMock]:
"""Mock Teslemetry Energy Specific live_status method."""
"""Mock Tesla Fleet API Energy Specific live_status method."""
with patch(
"homeassistant.components.tesla_fleet.EnergySpecific.live_status",
side_effect=lambda: deepcopy(LIVE_STATUS),
@ -116,7 +116,7 @@ def mock_live_status() -> Generator[AsyncMock]:
@pytest.fixture(autouse=True)
def mock_site_info() -> Generator[AsyncMock]:
"""Mock Teslemetry Energy Specific site_info method."""
"""Mock Tesla Fleet API Energy Specific site_info method."""
with patch(
"homeassistant.components.tesla_fleet.EnergySpecific.site_info",
side_effect=lambda: deepcopy(SITE_INFO),

View file

@ -1,8 +1,10 @@
"""Test the Tesla Fleet binary sensor platform."""
from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy import SnapshotAssertion
from syrupy.assertion import SnapshotAssertion
from tesla_fleet_api.exceptions import VehicleOffline
from homeassistant.components.tesla_fleet.coordinator import VEHICLE_INTERVAL
@ -34,7 +36,7 @@ async def test_binary_sensor_refresh(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
freezer: FrozenDateTimeFactory,
normal_config_entry: MockConfigEntry,
) -> None:
@ -53,7 +55,7 @@ async def test_binary_sensor_refresh(
async def test_binary_sensor_offline(
hass: HomeAssistant,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
normal_config_entry: MockConfigEntry,
) -> None:
"""Tests that the binary sensor entities are correct when offline."""

View file

@ -57,7 +57,7 @@ async def test_full_flow(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
access_token,
access_token: str,
) -> None:
"""Check full flow."""
result = await hass.config_entries.flow.async_init(
@ -121,7 +121,7 @@ async def test_full_flow_user_cred(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
access_token,
access_token: str,
) -> None:
"""Check full flow."""
@ -200,7 +200,7 @@ async def test_reauthentication(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
access_token,
access_token: str,
) -> None:
"""Test Tesla Fleet reauthentication."""
old_entry = MockConfigEntry(
@ -261,7 +261,7 @@ async def test_reauth_account_mismatch(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
access_token,
access_token: str,
) -> None:
"""Test Tesla Fleet reauthentication with different account."""
old_entry = MockConfigEntry(domain=DOMAIN, unique_id="baduid", version=1, data={})

View file

@ -1,6 +1,8 @@
"""Test the Tesla Fleet device tracker platform."""
from syrupy import SnapshotAssertion
from unittest.mock import AsyncMock
from syrupy.assertion import SnapshotAssertion
from tesla_fleet_api.exceptions import VehicleOffline
from homeassistant.const import STATE_UNKNOWN, Platform
@ -26,7 +28,7 @@ async def test_device_tracker(
async def test_device_tracker_offline(
hass: HomeAssistant,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
normal_config_entry: MockConfigEntry,
) -> None:
"""Tests that the device tracker entities are correct when offline."""

View file

@ -4,7 +4,7 @@ from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy import SnapshotAssertion
from syrupy.assertion import SnapshotAssertion
from tesla_fleet_api.exceptions import (
InvalidToken,
LoginRequired,
@ -59,9 +59,9 @@ async def test_load_unload(
async def test_init_error(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_products,
side_effect,
state,
mock_products: AsyncMock,
side_effect: TeslaFleetError,
state: ConfigEntryState,
) -> None:
"""Test init with errors."""
@ -91,8 +91,8 @@ async def test_devices(
async def test_vehicle_refresh_offline(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_vehicle_state,
mock_vehicle_data,
mock_vehicle_state: AsyncMock,
mock_vehicle_data: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test coordinator refresh with an error."""
@ -148,7 +148,7 @@ async def test_vehicle_refresh_error(
async def test_vehicle_refresh_ratelimited(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test coordinator refresh handles 429."""
@ -179,7 +179,7 @@ async def test_vehicle_refresh_ratelimited(
async def test_vehicle_sleep(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test coordinator refresh with an error."""
@ -241,9 +241,9 @@ async def test_vehicle_sleep(
async def test_energy_live_refresh_error(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_live_status,
side_effect,
state,
mock_live_status: AsyncMock,
side_effect: TeslaFleetError,
state: ConfigEntryState,
) -> None:
"""Test coordinator refresh with an error."""
mock_live_status.side_effect = side_effect
@ -256,9 +256,9 @@ async def test_energy_live_refresh_error(
async def test_energy_site_refresh_error(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_site_info,
side_effect,
state,
mock_site_info: AsyncMock,
side_effect: TeslaFleetError,
state: ConfigEntryState,
) -> None:
"""Test coordinator refresh with an error."""
mock_site_info.side_effect = side_effect
@ -300,7 +300,7 @@ async def test_energy_live_refresh_ratelimited(
async def test_energy_info_refresh_ratelimited(
hass: HomeAssistant,
normal_config_entry: MockConfigEntry,
mock_site_info,
mock_site_info: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test coordinator refresh handles 429."""

View file

@ -1,8 +1,10 @@
"""Test the Tesla Fleet sensor platform."""
from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy import SnapshotAssertion
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.tesla_fleet.coordinator import VEHICLE_INTERVAL
from homeassistant.const import Platform
@ -22,7 +24,7 @@ async def test_sensors(
normal_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
freezer: FrozenDateTimeFactory,
mock_vehicle_data,
mock_vehicle_data: AsyncMock,
) -> None:
"""Tests that the sensor entities are correct."""