Freeze config entry data (#32615)

* Freeze config entry data

* Fix mutating entry.data

* Fix config entry options tests
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-03-09 14:07:50 -07:00
1 parent 3318e65948
commit d4615fd432
16 files changed
+71 -45

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ async def test_setup_entry(hass):
async def test_setup_entry_fails(hass):
"""Test successful setup of entry."""
config_entry = MockConfigEntry(
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, options=True, version=2
domain=axis.DOMAIN, data={axis.CONF_MAC: "0123"}, version=2
)
config_entry.add_to_hass(hass)
@@ -196,7 +196,7 @@ async def test_hap_with_name(hass, mock_connection, hmip_config_entry):
entity_name = f"{home_name} Treppe"
device_model = "HmIP-BSL"
hmip_config_entry.data["name"] = home_name
hmip_config_entry.data = {**hmip_config_entry.data, "name": home_name}
mock_hap = await HomeFactory(
hass, mock_connection, hmip_config_entry
).async_get_mock_hap(test_devices=["Treppe"])
+4 -5
View File
@@ -73,11 +73,10 @@ async def test_flow_entry_already_exists(hass):
Test when the form should show when user puts existing location
in the config gui. Then the form should show with error.
"""
first_entry = MockConfigEntry(domain="met")
first_entry.data["name"] = "home"
first_entry.data[CONF_LONGITUDE] = 0
first_entry.data[CONF_LATITUDE] = 0
first_entry.data[CONF_ELEVATION] = 0
first_entry = MockConfigEntry(
domain="met",
data={"name": "home", CONF_LATITUDE: 0, CONF_LONGITUDE: 0, CONF_ELEVATION: 0},
)
first_entry.add_to_hass(hass)
test_data = {
+2 -2
View File
@@ -33,10 +33,10 @@ async def setup_mikrotik_entry(hass, **kwargs):
config_entry.add_to_hass(hass)
if "force_dhcp" in kwargs:
config_entry.options["force_dhcp"] = True
config_entry.options = {**config_entry.options, "force_dhcp": True}
if "arp_ping" in kwargs:
config_entry.options["arp_ping"] = True
config_entry.options = {**config_entry.options, "arp_ping": True}
with patch("librouteros.connect"), patch.object(
mikrotik.hub.MikrotikData, "command", new=mock_command
@@ -316,9 +316,10 @@ async def test_ssdp_already_configured(hass, remote):
DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA
)
assert result["type"] == "create_entry"
assert result["data"][CONF_MANUFACTURER] is None
assert result["data"][CONF_MODEL] is None
assert result["data"][CONF_ID] is None
entry = result["result"]
assert entry.data[CONF_MANUFACTURER] is None
assert entry.data[CONF_MODEL] is None
assert entry.data[CONF_ID] is None
# failed as already configured
result2 = await hass.config_entries.flow.async_init(
@@ -328,9 +329,9 @@ async def test_ssdp_already_configured(hass, remote):
assert result2["reason"] == "already_configured"
# check updated device info
assert result["data"][CONF_MANUFACTURER] == "fake_manufacturer"
assert result["data"][CONF_MODEL] == "fake_model"
assert result["data"][CONF_ID] == "fake_uuid"
assert entry.data[CONF_MANUFACTURER] == "fake_manufacturer"
assert entry.data[CONF_MODEL] == "fake_model"
assert entry.data[CONF_ID] == "fake_uuid"
async def test_autodetect_websocket(hass, remote):
+8 -2
View File
@@ -423,7 +423,10 @@ async def test_event_handler_dispatches_updated_devices(
data={"codeId": "1"},
)
request = event_request_factory(device_ids=device_ids, events=[event])
config_entry.data[CONF_INSTALLED_APP_ID] = request.installed_app_id
config_entry.data = {
**config_entry.data,
CONF_INSTALLED_APP_ID: request.installed_app_id,
}
called = False
def signal(ids):
@@ -479,7 +482,10 @@ async def test_event_handler_fires_button_events(
device.device_id, capability="button", attribute="button", value="pushed"
)
request = event_request_factory(events=[event])
config_entry.data[CONF_INSTALLED_APP_ID] = request.installed_app_id
config_entry.data = {
**config_entry.data,
CONF_INSTALLED_APP_ID: request.installed_app_id,
}
called = False
def handler(evt):