From 9ff35d5a5a7a2e35ce67980dccd8cc46e0808f36 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 11 Oct 2024 14:14:29 +0200 Subject: [PATCH] Minor improvement of entity platform tests (#128158) * Minor improvement of entity platform tests * Fix snapshot --- .../snapshots/test_entity_platform.ambr | 37 +++++++++++++++++++ tests/helpers/test_entity_platform.py | 24 +++++------- 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 tests/helpers/snapshots/test_entity_platform.ambr diff --git a/tests/helpers/snapshots/test_entity_platform.ambr b/tests/helpers/snapshots/test_entity_platform.ambr new file mode 100644 index 00000000000..84cbb07bd73 --- /dev/null +++ b/tests/helpers/snapshots/test_entity_platform.ambr @@ -0,0 +1,37 @@ +# serializer version: 1 +# name: test_device_info_called + DeviceRegistryEntrySnapshot({ + 'area_id': 'heliport', + 'config_entries': , + 'configuration_url': 'http://192.168.0.100/config', + 'connections': set({ + tuple( + 'mac', + 'abcd', + ), + }), + 'disabled_by': None, + 'entry_type': , + 'hw_version': 'test-hw', + 'id': , + 'identifiers': set({ + tuple( + 'hue', + '1234', + ), + }), + 'is_new': False, + 'labels': set({ + }), + 'manufacturer': 'test-manuf', + 'model': 'test-model', + 'model_id': None, + 'name': 'test-name', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': None, + 'suggested_area': 'Heliport', + 'sw_version': 'test-sw', + 'via_device_id': , + }) +# --- diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index db83819085b..e80006dff84 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -8,6 +8,7 @@ from typing import Any from unittest.mock import ANY, AsyncMock, Mock, patch import pytest +from syrupy.assertion import SnapshotAssertion import voluptuous as vol from homeassistant.config_entries import ConfigEntry @@ -878,9 +879,9 @@ async def test_setup_entry( assert full_name in hass.config.components assert len(hass.states.async_entity_ids()) == 1 assert len(entity_registry.entities) == 1 - assert ( - entity_registry.entities["test_domain.test1"].config_entry_id == "super-mock-id" - ) + + entity_registry_entry = entity_registry.entities["test_domain.test1"] + assert entity_registry_entry.config_entry_id == "super-mock-id" async def test_setup_entry_platform_not_ready( @@ -1131,7 +1132,9 @@ async def test_add_entity_with_invalid_id( async def test_device_info_called( - hass: HomeAssistant, device_registry: dr.DeviceRegistry + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, ) -> None: """Test device info is forwarded correctly.""" config_entry = MockConfigEntry(entry_id="super-mock-id") @@ -1185,18 +1188,9 @@ async def test_device_info_called( assert len(hass.states.async_entity_ids()) == 2 device = device_registry.async_get_device(identifiers={("hue", "1234")}) - assert device is not None - assert device.identifiers == {("hue", "1234")} - assert device.configuration_url == "http://192.168.0.100/config" - assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "abcd")} - assert device.entry_type is dr.DeviceEntryType.SERVICE - assert device.manufacturer == "test-manuf" - assert device.model == "test-model" - assert device.name == "test-name" + assert device == snapshot + assert device.config_entries == {config_entry.entry_id} assert device.primary_config_entry == config_entry.entry_id - assert device.suggested_area == "Heliport" - assert device.sw_version == "test-sw" - assert device.hw_version == "test-hw" assert device.via_device_id == via.id