From 4d8941d4b7b798892d7f3183d57906ec4e2f6674 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Thu, 24 Aug 2023 22:40:45 +0200 Subject: [PATCH] Use snapshot assertion for onvif diagnostics test (#98982) --- .../onvif/snapshots/test_diagnostics.ambr | 74 ++++++++++++++++ tests/components/onvif/test_diagnostics.py | 84 ++----------------- 2 files changed, 80 insertions(+), 78 deletions(-) create mode 100644 tests/components/onvif/snapshots/test_diagnostics.ambr diff --git a/tests/components/onvif/snapshots/test_diagnostics.ambr b/tests/components/onvif/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..e10c8791ba9 --- /dev/null +++ b/tests/components/onvif/snapshots/test_diagnostics.ambr @@ -0,0 +1,74 @@ +# serializer version: 1 +# name: test_diagnostics + dict({ + 'config': dict({ + 'data': dict({ + 'host': '**REDACTED**', + 'name': 'TestCamera', + 'password': '**REDACTED**', + 'port': 80, + 'snapshot_auth': 'digest', + 'username': '**REDACTED**', + }), + 'disabled_by': None, + 'domain': 'onvif', + 'entry_id': '1', + 'options': dict({ + 'enable_webhooks': True, + 'extra_arguments': '-pred 1', + 'rtsp_transport': 'tcp', + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Mock Title', + 'unique_id': 'aa:bb:cc:dd:ee', + 'version': 1, + }), + 'device': dict({ + 'capabilities': dict({ + 'events': False, + 'imaging': True, + 'ptz': True, + 'snapshot': False, + }), + 'info': dict({ + 'fw_version': 'TestFirmwareVersion', + 'mac': 'aa:bb:cc:dd:ee', + 'manufacturer': 'TestManufacturer', + 'model': 'TestModel', + 'serial_number': 'ABCDEFGHIJK', + }), + 'profiles': list([ + dict({ + 'index': 0, + 'name': 'profile1', + 'ptz': None, + 'token': 'dummy', + 'video': dict({ + 'encoding': 'any', + 'resolution': dict({ + 'height': 480, + 'width': 640, + }), + }), + 'video_source_token': None, + }), + ]), + 'services': dict({ + }), + 'xaddrs': dict({ + }), + }), + 'events': dict({ + 'pullpoint_manager_state': dict({ + '__type': "", + 'repr': '', + }), + 'webhook_manager_state': dict({ + '__type': "", + 'repr': '', + }), + }), + }) +# --- diff --git a/tests/components/onvif/test_diagnostics.py b/tests/components/onvif/test_diagnostics.py index f87a5f0eff6..af7a68a6e0d 100644 --- a/tests/components/onvif/test_diagnostics.py +++ b/tests/components/onvif/test_diagnostics.py @@ -1,93 +1,21 @@ """Test ONVIF diagnostics.""" -from unittest.mock import ANY +from syrupy import SnapshotAssertion from homeassistant.core import HomeAssistant -from . import ( - FIRMWARE_VERSION, - MAC, - MANUFACTURER, - MODEL, - SERIAL_NUMBER, - setup_onvif_integration, -) +from . import setup_onvif_integration from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator async def test_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test generating diagnostics for a config entry.""" entry, _, _ = await setup_onvif_integration(hass) - diag = await get_diagnostics_for_config_entry(hass, hass_client, entry) - - assert diag == { - "config": { - "entry_id": "1", - "version": 1, - "domain": "onvif", - "title": "Mock Title", - "data": { - "name": "TestCamera", - "host": "**REDACTED**", - "port": 80, - "username": "**REDACTED**", - "password": "**REDACTED**", - "snapshot_auth": "digest", - }, - "options": { - "extra_arguments": "-pred 1", - "rtsp_transport": "tcp", - "enable_webhooks": True, - }, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "unique_id": "aa:bb:cc:dd:ee", - "disabled_by": None, - }, - "device": { - "info": { - "manufacturer": MANUFACTURER, - "model": MODEL, - "fw_version": FIRMWARE_VERSION, - "serial_number": SERIAL_NUMBER, - "mac": MAC, - }, - "capabilities": { - "snapshot": False, - "events": False, - "ptz": True, - "imaging": True, - }, - "profiles": [ - { - "index": 0, - "token": "dummy", - "name": "profile1", - "video": { - "encoding": "any", - "resolution": {"width": 640, "height": 480}, - }, - "ptz": None, - "video_source_token": None, - } - ], - "services": ANY, - "xaddrs": ANY, - }, - "events": { - "pullpoint_manager_state": { - "__type": "", - "repr": "", - }, - "webhook_manager_state": { - "__type": "", - "repr": "", - }, - }, - } + assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot