Improve deCONZ init tests (#47825)

Use patch.dict rather than deep copy to change DECONZ_WEB_REQUEST
This commit is contained in:
Robert Svensson 2021-03-12 21:02:15 +01:00 committed by GitHub
parent 597bf67f5a
commit 6b03c8d126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
"""Test deCONZ component setup process."""
import asyncio
from copy import deepcopy
from unittest.mock import patch
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)
aioclient_mock.clear_requests()
data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
get_state_response=data,
entry_id="2",
unique_id="01234E56789B",
)
data = {"config": {"bridgeid": "01234E56789B"}}
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
entry_id="2",
unique_id="01234E56789B",
)
assert len(hass.data[DECONZ_DOMAIN]) == 2
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)
aioclient_mock.clear_requests()
data = deepcopy(DECONZ_WEB_REQUEST)
data["config"]["bridgeid"] = "01234E56789B"
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
get_state_response=data,
entry_id="2",
unique_id="01234E56789B",
)
data = {"config": {"bridgeid": "01234E56789B"}}
with patch.dict(DECONZ_WEB_REQUEST, data):
config_entry2 = await setup_deconz_integration(
hass,
aioclient_mock,
entry_id="2",
unique_id="01234E56789B",
)
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)
assert entry.data == {CONF_API_KEY: "1", CONF_HOST: "2", CONF_PORT: "3"}
old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
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"
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{new_unique_id}-OLD"
assert registry.async_get(f"{LIGHT_DOMAIN}.new").unique_id == f"{new_unique_id}-NEW"
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)
old_entity = registry.async_get(f"{LIGHT_DOMAIN}.old")
assert old_entity.unique_id == f"{old_unique_id}-OLD"
assert registry.async_get(f"{LIGHT_DOMAIN}.old").unique_id == f"{old_unique_id}-OLD"