From 7801eeb063b02d2b8e4a6a84584d5c6d31a4d531 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:34:13 +0200 Subject: [PATCH] Use snapshot in onewire diagnostics tests (#92112) --- .../onewire/snapshots/test_diagnostics.ambr | 41 +++++++++++++++++++ tests/components/onewire/test_diagnostics.py | 23 +++-------- 2 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 tests/components/onewire/snapshots/test_diagnostics.ambr diff --git a/tests/components/onewire/snapshots/test_diagnostics.ambr b/tests/components/onewire/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..f51fca7e988 --- /dev/null +++ b/tests/components/onewire/snapshots/test_diagnostics.ambr @@ -0,0 +1,41 @@ +# serializer version: 1 +# name: test_entry_diagnostics[EF.111111111113] + dict({ + 'devices': list([ + dict({ + 'device_info': dict({ + 'identifiers': list([ + list([ + 'onewire', + 'EF.111111111113', + ]), + ]), + 'manufacturer': 'Hobby Boards', + 'model': 'HB_HUB', + 'name': 'EF.111111111113', + }), + 'family': 'EF', + 'id': 'EF.111111111113', + 'path': '/EF.111111111113/', + 'type': 'HB_HUB', + }), + ]), + 'entry': dict({ + 'data': dict({ + 'host': '**REDACTED**', + 'port': 1234, + }), + 'options': dict({ + 'device_options': dict({ + '28.222222222222': dict({ + 'precision': 'temperature9', + }), + '28.222222222223': dict({ + 'precision': 'temperature5', + }), + }), + }), + 'title': 'Mock Title', + }), + }) +# --- diff --git a/tests/components/onewire/test_diagnostics.py b/tests/components/onewire/test_diagnostics.py index a812110c3f3..4e108e41959 100644 --- a/tests/components/onewire/test_diagnostics.py +++ b/tests/components/onewire/test_diagnostics.py @@ -3,8 +3,8 @@ from collections.abc import Generator from unittest.mock import MagicMock, patch import pytest +from syrupy.assertion import SnapshotAssertion -from homeassistant.components.diagnostics import REDACTED from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant @@ -43,25 +43,14 @@ async def test_entry_diagnostics( hass_client: ClientSessionGenerator, owproxy: MagicMock, device_id: str, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "data": { - "host": REDACTED, - "port": 1234, - }, - "options": { - "device_options": { - "28.222222222222": {"precision": "temperature9"}, - "28.222222222223": {"precision": "temperature5"}, - } - }, - "title": "Mock Title", - }, - "devices": [DEVICE_DETAILS], - } + assert ( + await get_diagnostics_for_config_entry(hass, hass_client, config_entry) + == snapshot + )