mirror of
https://github.com/home-assistant/core.git
synced 2026-10-08 23:36:09 -04:00
96 lines
2.8 KiB
Python
96 lines
2.8 KiB
Python
"""Tests for the diagnostics data provided by the Sonos integration."""
|
|
|
|
import pytest
|
|
from syrupy.assertion import SnapshotAssertion
|
|
from syrupy.filters import paths
|
|
|
|
from homeassistant.components.sonos.const import DOMAIN
|
|
from homeassistant.components.sonos.diagnostics import TO_REDACT
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.device_registry import DeviceRegistry
|
|
|
|
from tests.common import MockConfigEntry
|
|
from tests.components.diagnostics import (
|
|
get_diagnostics_for_config_entry,
|
|
get_diagnostics_for_device,
|
|
)
|
|
from tests.typing import ClientSessionGenerator
|
|
|
|
|
|
async def test_diagnostics_config_entry(
|
|
hass: HomeAssistant,
|
|
hass_client: ClientSessionGenerator,
|
|
async_autosetup_sonos,
|
|
config_entry: MockConfigEntry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test diagnostics for config entry."""
|
|
|
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
|
|
|
# Exclude items that are timing dependent.
|
|
assert result == snapshot(
|
|
exclude=paths(
|
|
"current_timestamp",
|
|
"discovered.RINCON_test.event_stats.soco:from_didl_string",
|
|
"discovered.RINCON_test.sonos_group_entities",
|
|
)
|
|
)
|
|
|
|
|
|
async def test_diagnostics_device(
|
|
hass: HomeAssistant,
|
|
hass_client: ClientSessionGenerator,
|
|
device_registry: DeviceRegistry,
|
|
async_autosetup_sonos,
|
|
config_entry: MockConfigEntry,
|
|
snapshot: SnapshotAssertion,
|
|
) -> None:
|
|
"""Test diagnostics for device."""
|
|
|
|
TEST_DEVICE = "RINCON_test"
|
|
|
|
device_entry = device_registry.async_get_device_by_identifier(
|
|
(DOMAIN, TEST_DEVICE), config_entry.entry_id
|
|
)
|
|
assert device_entry is not None
|
|
|
|
result = await get_diagnostics_for_device(
|
|
hass, hass_client, config_entry, device_entry
|
|
)
|
|
|
|
assert result == snapshot(
|
|
exclude=paths(
|
|
"event_stats.soco:from_didl_string",
|
|
"sonos_group_entities",
|
|
)
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("key", sorted(TO_REDACT))
|
|
async def test_diagnostics_redacts_keys(
|
|
hass: HomeAssistant,
|
|
hass_client: ClientSessionGenerator,
|
|
async_autosetup_sonos,
|
|
config_entry: MockConfigEntry,
|
|
key: str,
|
|
) -> None:
|
|
"""Test sensitive keys are redacted at any level."""
|
|
speaker = config_entry.runtime_data.discovered["RINCON_test"]
|
|
speaker._last_event_cache = {
|
|
"zone_group_topology": {
|
|
key: "secret",
|
|
"nested": [{key: "secret", "keep": 1}],
|
|
}
|
|
}
|
|
|
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
|
|
|
assert "secret" not in str(result)
|
|
assert result["discovered"]["RINCON_test"]["_last_event_cache"] == {
|
|
"zone_group_topology": {
|
|
key: "**REDACTED**",
|
|
"nested": [{key: "**REDACTED**", "keep": 1}],
|
|
}
|
|
}
|