From 14f80560c005a8bb479ca78dbff7cd2d562f5d90 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 24 Aug 2023 08:14:46 +0200 Subject: [PATCH] Use snapshot assertion for Ridwell diagnostics test (#98919) --- tests/components/ridwell/conftest.py | 7 ++- .../ridwell/snapshots/test_diagnostics.ambr | 49 ++++++++++++++++++ tests/components/ridwell/test_diagnostics.py | 50 +++---------------- 3 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 tests/components/ridwell/snapshots/test_diagnostics.ambr diff --git a/tests/components/ridwell/conftest.py b/tests/components/ridwell/conftest.py index 87ca00c37c3..651c2a96388 100644 --- a/tests/components/ridwell/conftest.py +++ b/tests/components/ridwell/conftest.py @@ -56,7 +56,12 @@ def client_fixture(account): @pytest.fixture(name="config_entry") def config_entry_fixture(hass, config): """Define a config entry fixture.""" - entry = MockConfigEntry(domain=DOMAIN, unique_id=config[CONF_USERNAME], data=config) + entry = MockConfigEntry( + domain=DOMAIN, + unique_id=config[CONF_USERNAME], + data=config, + entry_id="11554ec901379b9cc8f5a6c1d11ce978", + ) entry.add_to_hass(hass) return entry diff --git a/tests/components/ridwell/snapshots/test_diagnostics.ambr b/tests/components/ridwell/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..a98374d2941 --- /dev/null +++ b/tests/components/ridwell/snapshots/test_diagnostics.ambr @@ -0,0 +1,49 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'data': list([ + dict({ + '_async_request': None, + 'event_id': 'event_123', + 'pickup_date': dict({ + '__type': "", + 'isoformat': '2022-01-24', + }), + 'pickups': list([ + dict({ + 'category': dict({ + '__type': "", + 'repr': "", + }), + 'name': 'Plastic Film', + 'offer_id': 'offer_123', + 'priority': 1, + 'product_id': 'product_123', + 'quantity': 1, + }), + ]), + 'state': dict({ + '__type': "", + 'repr': "", + }), + }), + ]), + 'entry': dict({ + 'data': dict({ + 'password': '**REDACTED**', + 'username': '**REDACTED**', + }), + 'disabled_by': None, + 'domain': 'ridwell', + 'entry_id': '11554ec901379b9cc8f5a6c1d11ce978', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': '**REDACTED**', + 'unique_id': '**REDACTED**', + 'version': 2, + }), + }) +# --- diff --git a/tests/components/ridwell/test_diagnostics.py b/tests/components/ridwell/test_diagnostics.py index e73b352f3d9..c87004a8e76 100644 --- a/tests/components/ridwell/test_diagnostics.py +++ b/tests/components/ridwell/test_diagnostics.py @@ -1,5 +1,6 @@ """Test Ridwell 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 @@ -11,47 +12,10 @@ async def test_entry_diagnostics( config_entry, hass_client: ClientSessionGenerator, setup_config_entry, + 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": 2, - "domain": "ridwell", - "title": REDACTED, - "data": {"username": REDACTED, "password": REDACTED}, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": REDACTED, - "disabled_by": None, - }, - "data": [ - { - "_async_request": None, - "event_id": "event_123", - "pickup_date": { - "__type": "", - "isoformat": "2022-01-24", - }, - "pickups": [ - { - "name": "Plastic Film", - "offer_id": "offer_123", - "priority": 1, - "product_id": "product_123", - "quantity": 1, - "category": { - "__type": "", - "repr": "", - }, - } - ], - "state": { - "__type": "", - "repr": "", - }, - } - ], - } + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + == snapshot + )