mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Improve test of config entry store (#105487)
* Improve test of config entry store * Tweak test
This commit is contained in:
parent
4c0fda9ca0
commit
94fd7d0353
18
tests/snapshots/test_config_entries.ambr
Normal file
18
tests/snapshots/test_config_entries.ambr
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_as_dict
|
||||||
|
dict({
|
||||||
|
'data': dict({
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'test',
|
||||||
|
'entry_id': 'mock-entry',
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': 'Mock Title',
|
||||||
|
'unique_id': None,
|
||||||
|
'version': 1,
|
||||||
|
})
|
||||||
|
# ---
|
@ -9,6 +9,7 @@ from typing import Any
|
|||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, loader
|
from homeassistant import config_entries, data_entry_flow, loader
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
@ -667,14 +668,43 @@ async def test_saving_and_loading(hass: HomeAssistant) -> None:
|
|||||||
for orig, loaded in zip(
|
for orig, loaded in zip(
|
||||||
hass.config_entries.async_entries(), manager.async_entries()
|
hass.config_entries.async_entries(), manager.async_entries()
|
||||||
):
|
):
|
||||||
assert orig.version == loaded.version
|
assert orig.as_dict() == loaded.as_dict()
|
||||||
assert orig.domain == loaded.domain
|
|
||||||
assert orig.title == loaded.title
|
|
||||||
assert orig.data == loaded.data
|
async def test_as_dict(snapshot: SnapshotAssertion) -> None:
|
||||||
assert orig.source == loaded.source
|
"""Test ConfigEntry.as_dict."""
|
||||||
assert orig.unique_id == loaded.unique_id
|
|
||||||
assert orig.pref_disable_new_entities == loaded.pref_disable_new_entities
|
# Ensure as_dict is not overridden
|
||||||
assert orig.pref_disable_polling == loaded.pref_disable_polling
|
assert MockConfigEntry.as_dict is config_entries.ConfigEntry.as_dict
|
||||||
|
|
||||||
|
excluded_from_dict = {
|
||||||
|
"supports_unload",
|
||||||
|
"supports_remove_device",
|
||||||
|
"state",
|
||||||
|
"_setup_lock",
|
||||||
|
"update_listeners",
|
||||||
|
"reason",
|
||||||
|
"_async_cancel_retry_setup",
|
||||||
|
"_on_unload",
|
||||||
|
"reload_lock",
|
||||||
|
"_reauth_lock",
|
||||||
|
"_tasks",
|
||||||
|
"_background_tasks",
|
||||||
|
"_integration_for_domain",
|
||||||
|
"_tries",
|
||||||
|
"_setup_again_job",
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = MockConfigEntry(entry_id="mock-entry")
|
||||||
|
|
||||||
|
# Make sure the expected keys are present
|
||||||
|
dict_repr = entry.as_dict()
|
||||||
|
for key in config_entries.ConfigEntry.__slots__:
|
||||||
|
assert key in dict_repr or key in excluded_from_dict
|
||||||
|
assert not (key in dict_repr and key in excluded_from_dict)
|
||||||
|
|
||||||
|
# Make sure the dict representation is as expected
|
||||||
|
assert dict_repr == snapshot
|
||||||
|
|
||||||
|
|
||||||
async def test_forward_entry_sets_up_component(hass: HomeAssistant) -> None:
|
async def test_forward_entry_sets_up_component(hass: HomeAssistant) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user