1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Index config entries by id (#48199)

This commit is contained in:
J. Nick Koston
2021-03-21 18:44:29 -10:00
committed by GitHub
parent 6fab4a2c82
commit 3f2ca16ad7
7 changed files with 106 additions and 74 deletions

View File

@@ -7,7 +7,7 @@ import pytest
from homeassistant import config_entries, data_entry_flow, loader
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from homeassistant.util import dt
@@ -44,7 +44,7 @@ def mock_handlers():
def manager(hass):
"""Fixture of a loaded config manager."""
manager = config_entries.ConfigEntries(hass, {})
manager._entries = []
manager._entries = {}
manager._store._async_ensure_stop_listener = lambda: None
hass.config_entries = manager
return manager
@@ -1383,6 +1383,37 @@ async def test_unique_id_existing_entry(hass, manager):
assert len(async_remove_entry.mock_calls) == 1
async def test_entry_id_existing_entry(hass, manager):
"""Test that we throw when the entry id collides."""
collide_entry_id = "collide"
hass.config.components.add("comp")
MockConfigEntry(
entry_id=collide_entry_id,
domain="comp",
state=config_entries.ENTRY_STATE_LOADED,
unique_id="mock-unique-id",
).add_to_hass(hass)
class TestFlow(config_entries.ConfigFlow):
"""Test flow."""
VERSION = 1
async def async_step_user(self, user_input=None):
"""Test user step."""
return self.async_create_entry(title="mock-title", data={"via": "flow"})
with pytest.raises(HomeAssistantError), patch.dict(
config_entries.HANDLERS, {"comp": TestFlow}
), patch(
"homeassistant.config_entries.uuid_util.random_uuid_hex",
return_value=collide_entry_id,
):
await manager.flow.async_init(
"comp", context={"source": config_entries.SOURCE_USER}
)
async def test_unique_id_update_existing_entry_without_reload(hass, manager):
"""Test that we update an entry if there already is an entry with unique ID."""
hass.config.components.add("comp")