From 07ffbe82c183d792443ec90eef972882cfb13901 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 21 Aug 2023 19:46:36 +0200 Subject: [PATCH] Add snapshot assertion to Ambient Station (#98764) --- tests/components/ambient_station/conftest.py | 6 +- .../snapshots/test_diagnostics.ambr | 65 +++++++++++++++++++ .../ambient_station/test_diagnostics.py | 63 ++---------------- 3 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 tests/components/ambient_station/snapshots/test_diagnostics.ambr diff --git a/tests/components/ambient_station/conftest.py b/tests/components/ambient_station/conftest.py index aa849922b34..ab5eb6239c8 100644 --- a/tests/components/ambient_station/conftest.py +++ b/tests/components/ambient_station/conftest.py @@ -28,7 +28,11 @@ def config_fixture(hass): @pytest.fixture(name="config_entry") def config_entry_fixture(hass, config): """Define a config entry fixture.""" - entry = MockConfigEntry(domain=DOMAIN, data=config) + entry = MockConfigEntry( + domain=DOMAIN, + data=config, + entry_id="382cf7643f016fd48b3fe52163fe8877", + ) entry.add_to_hass(hass) return entry diff --git a/tests/components/ambient_station/snapshots/test_diagnostics.ambr b/tests/components/ambient_station/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..4b231660c4b --- /dev/null +++ b/tests/components/ambient_station/snapshots/test_diagnostics.ambr @@ -0,0 +1,65 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'entry': dict({ + 'data': dict({ + 'api_key': '**REDACTED**', + 'app_key': '**REDACTED**', + }), + 'disabled_by': None, + 'domain': 'ambient_station', + 'entry_id': '382cf7643f016fd48b3fe52163fe8877', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': '**REDACTED**', + 'unique_id': '**REDACTED**', + 'version': 2, + }), + 'stations': dict({ + 'devices': list([ + dict({ + 'apiKey': '**REDACTED**', + 'info': dict({ + 'location': '**REDACTED**', + 'name': 'Side Yard', + }), + 'lastData': dict({ + 'baromabsin': 25.016, + 'baromrelin': 29.953, + 'batt_co2': 1, + 'dailyrainin': 0, + 'date': '2022-01-19T22:38:00.000Z', + 'dateutc': 1642631880000, + 'deviceId': '**REDACTED**', + 'dewPoint': 17.75, + 'dewPointin': 37, + 'eventrainin': 0, + 'feelsLike': 21, + 'feelsLikein': 69.1, + 'hourlyrainin': 0, + 'humidity': 87, + 'humidityin': 29, + 'lastRain': '2022-01-07T19:45:00.000Z', + 'maxdailygust': 9.2, + 'monthlyrainin': 0.409, + 'solarradiation': 11.62, + 'tempf': 21, + 'tempinf': 70.9, + 'totalrainin': 35.398, + 'tz': '**REDACTED**', + 'uv': 0, + 'weeklyrainin': 0, + 'winddir': 25, + 'windgustmph': 1.1, + 'windspeedmph': 0.2, + }), + 'macAddress': '**REDACTED**', + }), + ]), + 'method': 'subscribe', + }), + }) +# --- diff --git a/tests/components/ambient_station/test_diagnostics.py b/tests/components/ambient_station/test_diagnostics.py index 61e974f4d0b..4c7a0f66f6a 100644 --- a/tests/components/ambient_station/test_diagnostics.py +++ b/tests/components/ambient_station/test_diagnostics.py @@ -1,6 +1,7 @@ """Test Ambient PWS diagnostics.""" +from syrupy import SnapshotAssertion + from homeassistant.components.ambient_station import DOMAIN -from homeassistant.components.diagnostics import REDACTED from homeassistant.core import HomeAssistant from tests.components.diagnostics import get_diagnostics_for_config_entry @@ -13,62 +14,12 @@ async def test_entry_diagnostics( hass_client: ClientSessionGenerator, data_station, setup_config_entry, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" ambient = hass.data[DOMAIN][config_entry.entry_id] ambient.stations = data_station - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "entry_id": config_entry.entry_id, - "version": 2, - "domain": "ambient_station", - "title": REDACTED, - "data": {"api_key": REDACTED, "app_key": REDACTED}, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": REDACTED, - "disabled_by": None, - }, - "stations": { - "devices": [ - { - "macAddress": REDACTED, - "lastData": { - "dateutc": 1642631880000, - "tempinf": 70.9, - "humidityin": 29, - "baromrelin": 29.953, - "baromabsin": 25.016, - "tempf": 21, - "humidity": 87, - "winddir": 25, - "windspeedmph": 0.2, - "windgustmph": 1.1, - "maxdailygust": 9.2, - "hourlyrainin": 0, - "eventrainin": 0, - "dailyrainin": 0, - "weeklyrainin": 0, - "monthlyrainin": 0.409, - "totalrainin": 35.398, - "solarradiation": 11.62, - "uv": 0, - "batt_co2": 1, - "feelsLike": 21, - "dewPoint": 17.75, - "feelsLikein": 69.1, - "dewPointin": 37, - "lastRain": "2022-01-07T19:45:00.000Z", - "deviceId": REDACTED, - "tz": REDACTED, - "date": "2022-01-19T22:38:00.000Z", - }, - "info": {"name": "Side Yard", "location": REDACTED}, - "apiKey": REDACTED, - } - ], - "method": "subscribe", - }, - } + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + == snapshot + )