Improve test of config entry store (#105487)

* Improve test of config entry store

* Tweak test
This commit is contained in:
Erik Montnemery 2023-12-11 16:48:12 +01:00 committed by GitHub
parent 4c0fda9ca0
commit 94fd7d0353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 8 deletions

View 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,
})
# ---

View File

@ -9,6 +9,7 @@ from typing import Any
from unittest.mock import AsyncMock, Mock, patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.components import dhcp
@ -667,14 +668,43 @@ async def test_saving_and_loading(hass: HomeAssistant) -> None:
for orig, loaded in zip(
hass.config_entries.async_entries(), manager.async_entries()
):
assert orig.version == loaded.version
assert orig.domain == loaded.domain
assert orig.title == loaded.title
assert orig.data == loaded.data
assert orig.source == loaded.source
assert orig.unique_id == loaded.unique_id
assert orig.pref_disable_new_entities == loaded.pref_disable_new_entities
assert orig.pref_disable_polling == loaded.pref_disable_polling
assert orig.as_dict() == loaded.as_dict()
async def test_as_dict(snapshot: SnapshotAssertion) -> None:
"""Test ConfigEntry.as_dict."""
# Ensure as_dict is not overridden
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: