mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Move nest diagnostic tests to use snapshots (#117929)
This commit is contained in:
parent
0c5296b38f
commit
7a6b107248
@ -164,7 +164,7 @@ async def create_device(
|
||||
device_id: str,
|
||||
device_type: str,
|
||||
device_traits: dict[str, Any],
|
||||
) -> None:
|
||||
) -> CreateDevice:
|
||||
"""Fixture for creating devices."""
|
||||
factory = CreateDevice(device_manager, auth)
|
||||
factory.data.update(
|
||||
|
83
tests/components/nest/snapshots/test_diagnostics.ambr
Normal file
83
tests/components/nest/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,83 @@
|
||||
# serializer version: 1
|
||||
# name: test_camera_diagnostics
|
||||
dict({
|
||||
'camera': dict({
|
||||
'camera.camera': dict({
|
||||
}),
|
||||
}),
|
||||
'devices': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'name': '**REDACTED**',
|
||||
'traits': dict({
|
||||
'sdm.devices.traits.CameraLiveStream': dict({
|
||||
'supportedProtocols': list([
|
||||
'RTSP',
|
||||
]),
|
||||
'videoCodecs': list([
|
||||
'H264',
|
||||
]),
|
||||
}),
|
||||
}),
|
||||
'type': 'sdm.devices.types.CAMERA',
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
||||
# name: test_device_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'assignee': '**REDACTED**',
|
||||
'name': '**REDACTED**',
|
||||
'parentRelations': list([
|
||||
dict({
|
||||
'displayName': '**REDACTED**',
|
||||
'parent': '**REDACTED**',
|
||||
}),
|
||||
]),
|
||||
'traits': dict({
|
||||
'sdm.devices.traits.Humidity': dict({
|
||||
'ambientHumidityPercent': 35.0,
|
||||
}),
|
||||
'sdm.devices.traits.Info': dict({
|
||||
'customName': '**REDACTED**',
|
||||
}),
|
||||
'sdm.devices.traits.Temperature': dict({
|
||||
'ambientTemperatureCelsius': 25.1,
|
||||
}),
|
||||
}),
|
||||
'type': 'sdm.devices.types.THERMOSTAT',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'devices': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'assignee': '**REDACTED**',
|
||||
'name': '**REDACTED**',
|
||||
'parentRelations': list([
|
||||
dict({
|
||||
'displayName': '**REDACTED**',
|
||||
'parent': '**REDACTED**',
|
||||
}),
|
||||
]),
|
||||
'traits': dict({
|
||||
'sdm.devices.traits.Humidity': dict({
|
||||
'ambientHumidityPercent': 35.0,
|
||||
}),
|
||||
'sdm.devices.traits.Info': dict({
|
||||
'customName': '**REDACTED**',
|
||||
}),
|
||||
'sdm.devices.traits.Temperature': dict({
|
||||
'ambientTemperatureCelsius': 25.1,
|
||||
}),
|
||||
}),
|
||||
'type': 'sdm.devices.types.THERMOSTAT',
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
@ -4,12 +4,16 @@ from unittest.mock import patch
|
||||
|
||||
from google_nest_sdm.exceptions import SubscriberException
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.nest.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .conftest import CreateDevice, PlatformSetup
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import (
|
||||
get_diagnostics_for_config_entry,
|
||||
get_diagnostics_for_device,
|
||||
@ -41,21 +45,6 @@ DEVICE_API_DATA = {
|
||||
],
|
||||
}
|
||||
|
||||
DEVICE_DIAGNOSTIC_DATA = {
|
||||
"data": {
|
||||
"assignee": "**REDACTED**",
|
||||
"name": "**REDACTED**",
|
||||
"parentRelations": [{"displayName": "**REDACTED**", "parent": "**REDACTED**"}],
|
||||
"traits": {
|
||||
"sdm.devices.traits.Info": {"customName": "**REDACTED**"},
|
||||
"sdm.devices.traits.Humidity": {"ambientHumidityPercent": 35.0},
|
||||
"sdm.devices.traits.Temperature": {"ambientTemperatureCelsius": 25.1},
|
||||
},
|
||||
"type": "sdm.devices.types.THERMOSTAT",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CAMERA_API_DATA = {
|
||||
"name": NEST_DEVICE_ID,
|
||||
"type": "sdm.devices.types.CAMERA",
|
||||
@ -67,19 +56,6 @@ CAMERA_API_DATA = {
|
||||
},
|
||||
}
|
||||
|
||||
CAMERA_DIAGNOSTIC_DATA = {
|
||||
"data": {
|
||||
"name": "**REDACTED**",
|
||||
"traits": {
|
||||
"sdm.devices.traits.CameraLiveStream": {
|
||||
"videoCodecs": ["H264"],
|
||||
"supportedProtocols": ["RTSP"],
|
||||
},
|
||||
},
|
||||
"type": "sdm.devices.types.CAMERA",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platforms() -> list[str]:
|
||||
@ -90,9 +66,10 @@ def platforms() -> list[str]:
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=DEVICE_API_DATA)
|
||||
@ -100,17 +77,19 @@ async def test_entry_diagnostics(
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
# Test that only non identifiable device information is returned
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
"devices": [DEVICE_DIAGNOSTIC_DATA]
|
||||
}
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
|
||||
|
||||
async def test_device_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=DEVICE_API_DATA)
|
||||
@ -123,15 +102,15 @@ async def test_device_diagnostics(
|
||||
|
||||
assert (
|
||||
await get_diagnostics_for_device(hass, hass_client, config_entry, device)
|
||||
== DEVICE_DIAGNOSTIC_DATA
|
||||
== snapshot
|
||||
)
|
||||
|
||||
|
||||
async def test_setup_susbcriber_failure(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry,
|
||||
setup_base_platform,
|
||||
config_entry: MockConfigEntry,
|
||||
setup_base_platform: PlatformSetup,
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
with patch(
|
||||
@ -148,9 +127,10 @@ async def test_setup_susbcriber_failure(
|
||||
async def test_camera_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
create_device,
|
||||
setup_platform,
|
||||
config_entry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
create_device.create(raw_data=CAMERA_API_DATA)
|
||||
@ -158,7 +138,7 @@ async def test_camera_diagnostics(
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
# Test that only non identifiable device information is returned
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
"devices": [CAMERA_DIAGNOSTIC_DATA],
|
||||
"camera": {"camera.camera": {}},
|
||||
}
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user