From 4518dad83b47d63b76912c444ab4be159bc6af18 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 21 Aug 2023 14:19:21 +0200 Subject: [PATCH] Use snapshot assertion for Airnow diagnostics (#98727) --- tests/components/airnow/conftest.py | 1 + .../airnow/snapshots/test_diagnostics.ambr | 39 +++++++++++++++ tests/components/airnow/test_diagnostics.py | 48 +++++-------------- 3 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 tests/components/airnow/snapshots/test_diagnostics.ambr diff --git a/tests/components/airnow/conftest.py b/tests/components/airnow/conftest.py index 47f20ccd883..15298ef3db0 100644 --- a/tests/components/airnow/conftest.py +++ b/tests/components/airnow/conftest.py @@ -16,6 +16,7 @@ def config_entry_fixture(hass, config): """Define a config entry fixture.""" entry = MockConfigEntry( domain=DOMAIN, + entry_id="3bd2acb0e4f0476d40865546d0d91921", unique_id=f"{config[CONF_LATITUDE]}-{config[CONF_LONGITUDE]}", data=config, ) diff --git a/tests/components/airnow/snapshots/test_diagnostics.ambr b/tests/components/airnow/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..ca333bbff72 --- /dev/null +++ b/tests/components/airnow/snapshots/test_diagnostics.ambr @@ -0,0 +1,39 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'data': dict({ + 'AQI': 44, + 'Category.Name': 'Good', + 'Category.Number': 1, + 'DateObserved': '2020-12-20', + 'HourObserved': 15, + 'Latitude': '**REDACTED**', + 'Longitude': '**REDACTED**', + 'O3': 0.048, + 'PM10': 12, + 'PM2.5': 8.9, + 'Pollutant': 'O3', + 'ReportingArea': '**REDACTED**', + 'StateCode': '**REDACTED**', + }), + 'entry': dict({ + 'data': dict({ + 'api_key': '**REDACTED**', + 'latitude': '**REDACTED**', + 'longitude': '**REDACTED**', + 'radius': 75, + }), + 'disabled_by': None, + 'domain': 'airnow', + 'entry_id': '3bd2acb0e4f0476d40865546d0d91921', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': '**REDACTED**', + 'unique_id': '**REDACTED**', + 'version': 1, + }), + }) +# --- diff --git a/tests/components/airnow/test_diagnostics.py b/tests/components/airnow/test_diagnostics.py index 38049cfec4b..ecf6acc1c80 100644 --- a/tests/components/airnow/test_diagnostics.py +++ b/tests/components/airnow/test_diagnostics.py @@ -1,5 +1,6 @@ """Test AirNow diagnostics.""" -from homeassistant.components.diagnostics import REDACTED +from syrupy import SnapshotAssertion + from homeassistant.core import HomeAssistant from tests.components.diagnostics import get_diagnostics_for_config_entry @@ -7,41 +8,14 @@ from tests.typing import ClientSessionGenerator async def test_entry_diagnostics( - hass: HomeAssistant, config_entry, hass_client: ClientSessionGenerator, setup_airnow + hass: HomeAssistant, + config_entry, + hass_client: ClientSessionGenerator, + setup_airnow, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "entry_id": config_entry.entry_id, - "version": 1, - "domain": "airnow", - "title": REDACTED, - "data": { - "api_key": REDACTED, - "latitude": REDACTED, - "longitude": REDACTED, - "radius": 75, - }, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": REDACTED, - "disabled_by": None, - }, - "data": { - "O3": 0.048, - "PM2.5": 8.9, - "HourObserved": 15, - "DateObserved": "2020-12-20", - "StateCode": REDACTED, - "ReportingArea": REDACTED, - "Latitude": REDACTED, - "Longitude": REDACTED, - "PM10": 12, - "AQI": 44, - "Category.Number": 1, - "Category.Name": "Good", - "Pollutant": "O3", - }, - } + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + == snapshot + )