From 5ad97827cf30ece4d734eea8814fc442fb6c1740 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 22 Aug 2023 12:17:43 +0200 Subject: [PATCH] Use snapshot assertion for Airly diagnostics (#98726) --- tests/components/airly/__init__.py | 1 + .../airly/fixtures/diagnostics_data.json | 28 ---------- .../airly/snapshots/test_diagnostics.ambr | 52 +++++++++++++++++++ tests/components/airly/test_diagnostics.py | 28 ++-------- 4 files changed, 57 insertions(+), 52 deletions(-) delete mode 100644 tests/components/airly/fixtures/diagnostics_data.json create mode 100644 tests/components/airly/snapshots/test_diagnostics.ambr diff --git a/tests/components/airly/__init__.py b/tests/components/airly/__init__.py index 452df6d9c27..ca26dbaf87f 100644 --- a/tests/components/airly/__init__.py +++ b/tests/components/airly/__init__.py @@ -14,6 +14,7 @@ async def init_integration(hass, aioclient_mock) -> MockConfigEntry: entry = MockConfigEntry( domain=DOMAIN, title="Home", + entry_id="3bd2acb0e4f0476d40865546d0d91921", unique_id="123-456", data={ "api_key": "foo", diff --git a/tests/components/airly/fixtures/diagnostics_data.json b/tests/components/airly/fixtures/diagnostics_data.json deleted file mode 100644 index 0f225fd4a20..00000000000 --- a/tests/components/airly/fixtures/diagnostics_data.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "PM1": 2.83, - "PM25": 4.37, - "PM10": 6.06, - "CO": 162.49, - "NO2": 16.04, - "O3": 41.52, - "SO2": 13.97, - "PRESSURE": 1019.86, - "HUMIDITY": 68.35, - "TEMPERATURE": 14.37, - "PM25_LIMIT": 15.0, - "PM25_PERCENT": 29.13, - "PM10_LIMIT": 45.0, - "PM10_PERCENT": 14.5, - "CO_LIMIT": 4000, - "CO_PERCENT": 4.06, - "NO2_LIMIT": 25, - "NO2_PERCENT": 64.17, - "O3_LIMIT": 100, - "O3_PERCENT": 41.52, - "SO2_LIMIT": 40, - "SO2_PERCENT": 34.93, - "CAQI": 7.29, - "LEVEL": "very low", - "DESCRIPTION": "Great air here today!", - "ADVICE": "Catch your breath!" -} diff --git a/tests/components/airly/snapshots/test_diagnostics.ambr b/tests/components/airly/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..a224ea07d46 --- /dev/null +++ b/tests/components/airly/snapshots/test_diagnostics.ambr @@ -0,0 +1,52 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'config_entry': dict({ + 'data': dict({ + 'api_key': '**REDACTED**', + 'latitude': '**REDACTED**', + 'longitude': '**REDACTED**', + 'name': 'Home', + }), + 'disabled_by': None, + 'domain': 'airly', + 'entry_id': '3bd2acb0e4f0476d40865546d0d91921', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Home', + 'unique_id': '**REDACTED**', + 'version': 1, + }), + 'coordinator_data': dict({ + 'ADVICE': 'Catch your breath!', + 'CAQI': 7.29, + 'CO': 162.49, + 'CO_LIMIT': 4000, + 'CO_PERCENT': 4.06, + 'DESCRIPTION': 'Great air here today!', + 'HUMIDITY': 68.35, + 'LEVEL': 'very low', + 'NO2': 16.04, + 'NO2_LIMIT': 25, + 'NO2_PERCENT': 64.17, + 'O3': 41.52, + 'O3_LIMIT': 100, + 'O3_PERCENT': 41.52, + 'PM1': 2.83, + 'PM10': 6.06, + 'PM10_LIMIT': 45, + 'PM10_PERCENT': 14.5, + 'PM25': 4.37, + 'PM25_LIMIT': 15, + 'PM25_PERCENT': 29.13, + 'PRESSURE': 1019.86, + 'SO2': 13.97, + 'SO2_LIMIT': 40, + 'SO2_PERCENT': 34.93, + 'TEMPERATURE': 14.37, + }), + }) +# --- diff --git a/tests/components/airly/test_diagnostics.py b/tests/components/airly/test_diagnostics.py index 611f7910ae7..7364824e594 100644 --- a/tests/components/airly/test_diagnostics.py +++ b/tests/components/airly/test_diagnostics.py @@ -1,12 +1,11 @@ """Test Airly diagnostics.""" -import json -from homeassistant.components.diagnostics import REDACTED +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.test_util.aiohttp import AiohttpClientMocker from tests.typing import ClientSessionGenerator @@ -16,30 +15,11 @@ async def test_entry_diagnostics( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" entry = await init_integration(hass, aioclient_mock) - coordinator_data = json.loads(load_fixture("diagnostics_data.json", "airly")) - result = await get_diagnostics_for_config_entry(hass, hass_client, entry) - assert result["config_entry"] == { - "entry_id": entry.entry_id, - "version": 1, - "domain": "airly", - "title": "Home", - "data": { - "latitude": REDACTED, - "longitude": REDACTED, - "name": "Home", - "api_key": REDACTED, - }, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": REDACTED, - "disabled_by": None, - } - assert result["coordinator_data"] == coordinator_data + assert result == snapshot