From f96c1516f83194ce94d1ffc743386452481fa584 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Fri, 25 Aug 2023 16:46:10 +0200 Subject: [PATCH] Use snapshot assertion for gios diagnostics test (#98984) --- tests/components/gios/__init__.py | 1 + .../gios/fixtures/diagnostics_data.json | 50 ------------- .../gios/snapshots/test_diagnostics.ambr | 72 +++++++++++++++++++ tests/components/gios/test_diagnostics.py | 30 ++------ 4 files changed, 79 insertions(+), 74 deletions(-) delete mode 100644 tests/components/gios/fixtures/diagnostics_data.json create mode 100644 tests/components/gios/snapshots/test_diagnostics.ambr diff --git a/tests/components/gios/__init__.py b/tests/components/gios/__init__.py index 6c39ee35303..946cceac786 100644 --- a/tests/components/gios/__init__.py +++ b/tests/components/gios/__init__.py @@ -21,6 +21,7 @@ async def init_integration( title="Home", unique_id="123", data={"station_id": 123, "name": "Home"}, + entry_id="86129426118ae32020417a53712d6eef", ) indexes = json.loads(load_fixture("gios/indexes.json")) diff --git a/tests/components/gios/fixtures/diagnostics_data.json b/tests/components/gios/fixtures/diagnostics_data.json deleted file mode 100644 index feee534ec31..00000000000 --- a/tests/components/gios/fixtures/diagnostics_data.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "aqi": { - "name": "AQI", - "id": null, - "index": null, - "value": "good" - }, - "c6h6": { - "name": "benzene", - "id": 658, - "index": "very_good", - "value": 0.23789 - }, - "co": { - "name": "carbon monoxide", - "id": 660, - "index": "good", - "value": 251.874 - }, - "no2": { - "name": "nitrogen dioxide", - "id": 665, - "index": "good", - "value": 7.13411 - }, - "o3": { - "name": "ozone", - "id": 667, - "index": "good", - "value": 95.7768 - }, - "pm10": { - "name": "particulate matter 10", - "id": 14395, - "index": "good", - "value": 16.8344 - }, - "pm25": { - "name": "particulate matter 2.5", - "id": 670, - "index": "good", - "value": 4 - }, - "so2": { - "name": "sulfur dioxide", - "id": 672, - "index": "very_good", - "value": 4.35478 - } -} diff --git a/tests/components/gios/snapshots/test_diagnostics.ambr b/tests/components/gios/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..67691602fcf --- /dev/null +++ b/tests/components/gios/snapshots/test_diagnostics.ambr @@ -0,0 +1,72 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'config_entry': dict({ + 'data': dict({ + 'name': 'Home', + 'station_id': 123, + }), + 'disabled_by': None, + 'domain': 'gios', + 'entry_id': '86129426118ae32020417a53712d6eef', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Home', + 'unique_id': '123', + 'version': 1, + }), + 'coordinator_data': dict({ + 'aqi': dict({ + 'id': None, + 'index': None, + 'name': 'AQI', + 'value': 'good', + }), + 'c6h6': dict({ + 'id': 658, + 'index': 'very_good', + 'name': 'benzene', + 'value': 0.23789, + }), + 'co': dict({ + 'id': 660, + 'index': 'good', + 'name': 'carbon monoxide', + 'value': 251.874, + }), + 'no2': dict({ + 'id': 665, + 'index': 'good', + 'name': 'nitrogen dioxide', + 'value': 7.13411, + }), + 'o3': dict({ + 'id': 667, + 'index': 'good', + 'name': 'ozone', + 'value': 95.7768, + }), + 'pm10': dict({ + 'id': 14395, + 'index': 'good', + 'name': 'particulate matter 10', + 'value': 16.8344, + }), + 'pm25': dict({ + 'id': 670, + 'index': 'good', + 'name': 'particulate matter 2.5', + 'value': 4, + }), + 'so2': dict({ + 'id': 672, + 'index': 'very_good', + 'name': 'sulfur dioxide', + 'value': 4.35478, + }), + }), + }) +# --- diff --git a/tests/components/gios/test_diagnostics.py b/tests/components/gios/test_diagnostics.py index 0b9560a96e1..903de4872a2 100644 --- a/tests/components/gios/test_diagnostics.py +++ b/tests/components/gios/test_diagnostics.py @@ -1,39 +1,21 @@ """Test GIOS diagnostics.""" -import json + +from syrupy import SnapshotAssertion from homeassistant.core import HomeAssistant from . import init_integration -from tests.common import load_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry 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 init_integration(hass) - coordinator_data = json.loads(load_fixture("diagnostics_data.json", "gios")) - - result = await get_diagnostics_for_config_entry(hass, hass_client, entry) - - assert result["config_entry"] == { - "entry_id": entry.entry_id, - "version": 1, - "domain": "gios", - "title": "Home", - "data": { - "station_id": 123, - "name": "Home", - }, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": "123", - "disabled_by": None, - } - assert result["coordinator_data"] == coordinator_data + assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot