Use snapshot assertion for ESPHome diagnostics test (#98913)

This commit is contained in:
Joost Lekkerkerker 2023-08-24 01:01:58 +02:00 committed by GitHub
parent a539d851cc
commit f1fb28aad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 15 deletions

View file

@ -62,6 +62,7 @@ def mock_config_entry(hass) -> MockConfigEntry:
"""Return the default mocked config entry."""
config_entry = MockConfigEntry(
title="ESPHome Device",
entry_id="08d821dc059cf4f645cb024d32c8e708",
domain=DOMAIN,
data={
CONF_HOST: "192.168.1.2",

View file

@ -0,0 +1,26 @@
# serializer version: 1
# name: test_diagnostics
dict({
'config': dict({
'data': dict({
'device_name': 'test',
'host': '192.168.1.2',
'noise_psk': '**REDACTED**',
'password': '**REDACTED**',
'port': 6053,
}),
'disabled_by': None,
'domain': 'esphome',
'entry_id': '08d821dc059cf4f645cb024d32c8e708',
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'ESPHome Device',
'unique_id': '11:22:33:44:55:aa',
'version': 1,
}),
'dashboard': 'mock-slug',
})
# ---

View file

@ -1,12 +1,8 @@
"""Tests for the diagnostics data provided by the ESPHome integration."""
from syrupy import SnapshotAssertion
from homeassistant.components.esphome.const import CONF_DEVICE_NAME, CONF_NOISE_PSK
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
from homeassistant.core import HomeAssistant
from . import DASHBOARD_SLUG
from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
@ -18,17 +14,9 @@ async def test_diagnostics(
init_integration: MockConfigEntry,
enable_bluetooth: None,
mock_dashboard,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics for config entry."""
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
assert isinstance(result, dict)
assert result["config"]["data"] == {
CONF_DEVICE_NAME: "test",
CONF_HOST: "192.168.1.2",
CONF_PORT: 6053,
CONF_PASSWORD: "**REDACTED**",
CONF_NOISE_PSK: "**REDACTED**",
}
assert result["config"]["unique_id"] == "11:22:33:44:55:aa"
assert result["dashboard"] == DASHBOARD_SLUG
assert result == snapshot