From 860ac450c4fd2d676182ff10e03949129dd1e4b5 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 25 Apr 2024 22:23:13 +0200 Subject: [PATCH] Use snapshots in Linear diagnostics tests (#116169) * Use snapshots in Linear diagnostics tests * Use snapshots in Linear diagnostics tests --- .../snapshots/test_diagnostics.ambr | 79 +++++++++++++++++++ .../linear_garage_door/test_diagnostics.py | 44 ++--------- tests/components/linear_garage_door/util.py | 1 + 3 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 tests/components/linear_garage_door/snapshots/test_diagnostics.ambr diff --git a/tests/components/linear_garage_door/snapshots/test_diagnostics.ambr b/tests/components/linear_garage_door/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..72886410924 --- /dev/null +++ b/tests/components/linear_garage_door/snapshots/test_diagnostics.ambr @@ -0,0 +1,79 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'coordinator_data': dict({ + 'test1': dict({ + 'name': 'Test Garage 1', + 'subdevices': dict({ + 'GDO': dict({ + 'Open_B': 'true', + 'Open_P': '100', + }), + 'Light': dict({ + 'On_B': 'true', + 'On_P': '100', + }), + }), + }), + 'test2': dict({ + 'name': 'Test Garage 2', + 'subdevices': dict({ + 'GDO': dict({ + 'Open_B': 'false', + 'Open_P': '0', + }), + 'Light': dict({ + 'On_B': 'false', + 'On_P': '0', + }), + }), + }), + 'test3': dict({ + 'name': 'Test Garage 3', + 'subdevices': dict({ + 'GDO': dict({ + 'Open_B': 'false', + 'Opening_P': '0', + }), + 'Light': dict({ + 'On_B': 'false', + 'On_P': '0', + }), + }), + }), + 'test4': dict({ + 'name': 'Test Garage 4', + 'subdevices': dict({ + 'GDO': dict({ + 'Open_B': 'true', + 'Opening_P': '100', + }), + 'Light': dict({ + 'On_B': 'true', + 'On_P': '100', + }), + }), + }), + }), + 'entry': dict({ + 'data': dict({ + 'device_id': 'test-uuid', + 'email': '**REDACTED**', + 'password': '**REDACTED**', + 'site_id': 'test-site-id', + }), + 'disabled_by': None, + 'domain': 'linear_garage_door', + 'entry_id': 'acefdd4b3a4a0911067d1cf51414201e', + 'minor_version': 1, + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Mock Title', + 'unique_id': None, + 'version': 1, + }), + }) +# --- diff --git a/tests/components/linear_garage_door/test_diagnostics.py b/tests/components/linear_garage_door/test_diagnostics.py index 0650196d619..a9565441bbb 100644 --- a/tests/components/linear_garage_door/test_diagnostics.py +++ b/tests/components/linear_garage_door/test_diagnostics.py @@ -1,5 +1,7 @@ """Test diagnostics of Linear Garage Door.""" +from syrupy import SnapshotAssertion + from homeassistant.core import HomeAssistant from .util import async_init_integration @@ -9,45 +11,11 @@ from tests.typing import ClientSessionGenerator async def test_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" entry = await async_init_integration(hass) result = await get_diagnostics_for_config_entry(hass, hass_client, entry) - - assert result["entry"]["data"] == { - "email": "**REDACTED**", - "password": "**REDACTED**", - "site_id": "test-site-id", - "device_id": "test-uuid", - } - assert result["coordinator_data"] == { - "test1": { - "name": "Test Garage 1", - "subdevices": { - "GDO": {"Open_B": "true", "Open_P": "100"}, - "Light": {"On_B": "true", "On_P": "100"}, - }, - }, - "test2": { - "name": "Test Garage 2", - "subdevices": { - "GDO": {"Open_B": "false", "Open_P": "0"}, - "Light": {"On_B": "false", "On_P": "0"}, - }, - }, - "test3": { - "name": "Test Garage 3", - "subdevices": { - "GDO": {"Open_B": "false", "Opening_P": "0"}, - "Light": {"On_B": "false", "On_P": "0"}, - }, - }, - "test4": { - "name": "Test Garage 4", - "subdevices": { - "GDO": {"Open_B": "true", "Opening_P": "100"}, - "Light": {"On_B": "true", "On_P": "100"}, - }, - }, - } + assert result == snapshot diff --git a/tests/components/linear_garage_door/util.py b/tests/components/linear_garage_door/util.py index 1a849ae2348..30dbdbd06d5 100644 --- a/tests/components/linear_garage_door/util.py +++ b/tests/components/linear_garage_door/util.py @@ -12,6 +12,7 @@ async def async_init_integration(hass: HomeAssistant) -> MockConfigEntry: """Initialize mock integration.""" config_entry = MockConfigEntry( domain=DOMAIN, + entry_id="acefdd4b3a4a0911067d1cf51414201e", data={ "email": "test-email", "password": "test-password",