Avoid mutating globals in nina tests (#78513)

pull/78525/head
Erik Montnemery 2022-09-15 12:05:29 +02:00 committed by GitHub
parent ada1cff4b1
commit aa0fd8c935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,7 @@
"""Test the Nina config flow."""
from __future__ import annotations
from copy import deepcopy
import json
from typing import Any
from unittest.mock import patch
@ -70,7 +71,7 @@ async def test_step_user_connection_error(hass: HomeAssistant) -> None:
):
result: dict[str, Any] = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_DATA
DOMAIN, context={"source": SOURCE_USER}, data=deepcopy(DUMMY_DATA)
)
assert result["type"] == data_entry_flow.FlowResultType.FORM
@ -85,7 +86,7 @@ async def test_step_user_unexpected_exception(hass: HomeAssistant) -> None:
):
result: dict[str, Any] = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_DATA
DOMAIN, context={"source": SOURCE_USER}, data=deepcopy(DUMMY_DATA)
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
@ -102,7 +103,7 @@ async def test_step_user(hass: HomeAssistant) -> None:
):
result: dict[str, Any] = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_DATA
DOMAIN, context={"source": SOURCE_USER}, data=deepcopy(DUMMY_DATA)
)
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
@ -132,11 +133,11 @@ async def test_step_user_already_configured(hass: HomeAssistant) -> None:
wraps=mocked_request_function,
):
result: dict[str, Any] = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_DATA
DOMAIN, context={"source": SOURCE_USER}, data=deepcopy(DUMMY_DATA)
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=DUMMY_DATA
DOMAIN, context={"source": SOURCE_USER}, data=deepcopy(DUMMY_DATA)
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
@ -149,9 +150,9 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
domain=DOMAIN,
title="NINA",
data={
CONF_FILTER_CORONA: DUMMY_DATA[CONF_FILTER_CORONA],
CONF_MESSAGE_SLOTS: DUMMY_DATA[CONF_MESSAGE_SLOTS],
CONST_REGION_A_TO_D: DUMMY_DATA[CONST_REGION_A_TO_D],
CONF_FILTER_CORONA: deepcopy(DUMMY_DATA[CONF_FILTER_CORONA]),
CONF_MESSAGE_SLOTS: deepcopy(DUMMY_DATA[CONF_MESSAGE_SLOTS]),
CONST_REGION_A_TO_D: deepcopy(DUMMY_DATA[CONST_REGION_A_TO_D]),
CONF_REGIONS: {"095760000000": "Aach"},
},
)
@ -187,8 +188,8 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
assert result["data"] is None
assert dict(config_entry.data) == {
CONF_FILTER_CORONA: DUMMY_DATA[CONF_FILTER_CORONA],
CONF_MESSAGE_SLOTS: DUMMY_DATA[CONF_MESSAGE_SLOTS],
CONF_FILTER_CORONA: deepcopy(DUMMY_DATA[CONF_FILTER_CORONA]),
CONF_MESSAGE_SLOTS: deepcopy(DUMMY_DATA[CONF_MESSAGE_SLOTS]),
CONST_REGION_A_TO_D: ["072350000000_1"],
CONST_REGION_E_TO_H: [],
CONST_REGION_I_TO_L: [],
@ -206,7 +207,7 @@ async def test_options_flow_with_no_selection(hass: HomeAssistant) -> None:
config_entry = MockConfigEntry(
domain=DOMAIN,
title="NINA",
data=DUMMY_DATA,
data=deepcopy(DUMMY_DATA),
)
config_entry.add_to_hass(hass)
@ -246,7 +247,7 @@ async def test_options_flow_connection_error(hass: HomeAssistant) -> None:
config_entry = MockConfigEntry(
domain=DOMAIN,
title="NINA",
data=DUMMY_DATA,
data=deepcopy(DUMMY_DATA),
)
config_entry.add_to_hass(hass)
@ -271,7 +272,7 @@ async def test_options_flow_unexpected_exception(hass: HomeAssistant) -> None:
config_entry = MockConfigEntry(
domain=DOMAIN,
title="NINA",
data=DUMMY_DATA,
data=deepcopy(DUMMY_DATA),
)
config_entry.add_to_hass(hass)
@ -295,7 +296,7 @@ async def test_options_flow_entity_removal(hass: HomeAssistant) -> None:
config_entry = MockConfigEntry(
domain=DOMAIN,
title="NINA",
data=DUMMY_DATA,
data=deepcopy(DUMMY_DATA) | {CONF_REGIONS: {"095760000000": "Aach"}},
)
config_entry.add_to_hass(hass)