Skip to content

Commit

Permalink
Add snapshot testing to Tessie (home-assistant#108346)
Browse files Browse the repository at this point in the history
* Redo Binary Sensors

* Redo Button

* Redo Climate

* Stage unfixed platforms

* Redo Cover

* Redo device tracker

* Redo lock

* Redo Media Player

* Redo Number

* Redo Select

* Redo Sensor

* Redo Switch

* Redo Update

* Fix setup_platform

* Add mixing snapshot

* Fix config flow

* Centralise entity testing

* Update snapshot

* Rename test_entities

* Fix assert_entities
  • Loading branch information
Bre77 authored Jan 27, 2024
1 parent 950660b commit 858fb1f
Show file tree
Hide file tree
Showing 27 changed files with 5,827 additions and 310 deletions.
26 changes: 23 additions & 3 deletions tests/components/tessie/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

from aiohttp import ClientConnectionError, ClientResponseError
from aiohttp.client import RequestInfo
from syrupy import SnapshotAssertion

from homeassistant.components.tessie.const import DOMAIN, TessieStatus
from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

from tests.common import MockConfigEntry, load_json_object_fixture

Expand Down Expand Up @@ -44,7 +46,9 @@
ERROR_CONNECTION = ClientConnectionError()


async def setup_platform(hass: HomeAssistant, side_effect=None):
async def setup_platform(
hass: HomeAssistant, platforms: list[Platform] = [], side_effect=None
) -> MockConfigEntry:
"""Set up the Tessie platform."""

mock_entry = MockConfigEntry(
Expand All @@ -57,8 +61,24 @@ async def setup_platform(hass: HomeAssistant, side_effect=None):
"homeassistant.components.tessie.get_state_of_all_vehicles",
return_value=TEST_STATE_OF_ALL_VEHICLES,
side_effect=side_effect,
):
), patch("homeassistant.components.tessie.PLATFORMS", platforms):
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()

return mock_entry


def assert_entities(
hass: HomeAssistant,
entry_id: str,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test that all entities match their snapshot."""
entity_entries = er.async_entries_for_config_entry(entity_registry, entry_id)

assert entity_entries
for entity_entry in entity_entries:
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
assert (state := hass.states.get(entity_entry.entity_id))
assert state == snapshot(name=f"{entity_entry.entity_id}-state")
Loading

0 comments on commit 858fb1f

Please sign in to comment.