mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Improve deCONZ init tests (#47825)
Use patch.dict rather than deep copy to change DECONZ_WEB_REQUEST
This commit is contained in:
parent
597bf67f5a
commit
6b03c8d126
@ -1,7 +1,6 @@
|
|||||||
"""Test deCONZ component setup process."""
|
"""Test deCONZ component setup process."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from copy import deepcopy
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.deconz import (
|
from homeassistant.components.deconz import (
|
||||||
@ -71,15 +70,14 @@ async def test_setup_entry_multiple_gateways(hass, aioclient_mock):
|
|||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
aioclient_mock.clear_requests()
|
aioclient_mock.clear_requests()
|
||||||
|
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {"config": {"bridgeid": "01234E56789B"}}
|
||||||
data["config"]["bridgeid"] = "01234E56789B"
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry2 = await setup_deconz_integration(
|
config_entry2 = await setup_deconz_integration(
|
||||||
hass,
|
hass,
|
||||||
aioclient_mock,
|
aioclient_mock,
|
||||||
get_state_response=data,
|
entry_id="2",
|
||||||
entry_id="2",
|
unique_id="01234E56789B",
|
||||||
unique_id="01234E56789B",
|
)
|
||||||
)
|
|
||||||
|
|
||||||
assert len(hass.data[DECONZ_DOMAIN]) == 2
|
assert len(hass.data[DECONZ_DOMAIN]) == 2
|
||||||
assert hass.data[DECONZ_DOMAIN][config_entry.unique_id].master
|
assert hass.data[DECONZ_DOMAIN][config_entry.unique_id].master
|
||||||
@ -100,15 +98,14 @@ async def test_unload_entry_multiple_gateways(hass, aioclient_mock):
|
|||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
aioclient_mock.clear_requests()
|
aioclient_mock.clear_requests()
|
||||||
|
|
||||||
data = deepcopy(DECONZ_WEB_REQUEST)
|
data = {"config": {"bridgeid": "01234E56789B"}}
|
||||||
data["config"]["bridgeid"] = "01234E56789B"
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
config_entry2 = await setup_deconz_integration(
|
config_entry2 = await setup_deconz_integration(
|
||||||
hass,
|
hass,
|
||||||
aioclient_mock,
|
aioclient_mock,
|
||||||
get_state_response=data,
|
entry_id="2",
|
||||||
entry_id="2",
|
unique_id="01234E56789B",
|
||||||
unique_id="01234E56789B",
|
)
|
||||||
)
|
|
||||||
|
|
||||||
assert len(hass.data[DECONZ_DOMAIN]) == 2
|
assert len(hass.data[DECONZ_DOMAIN]) == 2
|
||||||
|
|
||||||
@ -154,12 +151,8 @@ async def test_update_group_unique_id(hass):
|
|||||||
await async_update_group_unique_id(hass, entry)
|
await async_update_group_unique_id(hass, entry)
|
||||||
|
|
||||||
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
|
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
|
||||||
|
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{new_unique_id}-OLD"
|
||||||
old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
|
assert registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id == f"{new_unique_id}-NEW"
|
||||||
assert old_entity.unique_id == f"{new_unique_id}-OLD"
|
|
||||||
|
|
||||||
new_entity = registry.async_get(f"{LIGHT_DOMAIN}.new")
|
|
||||||
assert new_entity.unique_id == f"{new_unique_id}-NEW"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_update_group_unique_id_no_legacy_group_id(hass):
|
async def test_update_group_unique_id_no_legacy_group_id(hass):
|
||||||
@ -184,5 +177,4 @@ async def test_update_group_unique_id_no_legacy_group_id(hass):
|
|||||||
|
|
||||||
await async_update_group_unique_id(hass, entry)
|
await async_update_group_unique_id(hass, entry)
|
||||||
|
|
||||||
old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
|
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{old_unique_id}-OLD"
|
||||||
assert old_entity.unique_id == f"{old_unique_id}-OLD"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user