mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Improve config_entries tests (#138274)
* Improve config_entries tests * Drop unnecessary use of OrderedDict
This commit is contained in:
parent
428cc1a951
commit
77486b9306
@ -1,6 +1,5 @@
|
|||||||
"""Test config entries API."""
|
"""Test config entries API."""
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -411,9 +410,10 @@ async def test_initialize_flow(hass: HomeAssistant, client: TestClient) -> None:
|
|||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
schema = OrderedDict()
|
schema = {
|
||||||
schema[vol.Required("username")] = str
|
vol.Required("username"): str,
|
||||||
schema[vol.Required("password")] = str
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
@ -493,13 +493,14 @@ async def test_initialize_flow_unauth(
|
|||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
schema = OrderedDict()
|
schema = {
|
||||||
schema[vol.Required("username")] = str
|
vol.Required("username"): str,
|
||||||
schema[vol.Required("password")] = str
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=schema,
|
data_schema=vol.Schema(schema),
|
||||||
description_placeholders={"url": "https://example.com"},
|
description_placeholders={"url": "https://example.com"},
|
||||||
errors={"username": "Should be unique."},
|
errors={"username": "Should be unique."},
|
||||||
)
|
)
|
||||||
@ -540,7 +541,7 @@ async def test_abort(hass: HomeAssistant, client: TestClient) -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("enable_custom_integrations", "freezer")
|
@pytest.mark.usefixtures("freezer")
|
||||||
async def test_create_account(hass: HomeAssistant, client: TestClient) -> None:
|
async def test_create_account(hass: HomeAssistant, client: TestClient) -> None:
|
||||||
"""Test a flow that creates an account."""
|
"""Test a flow that creates an account."""
|
||||||
mock_platform(hass, "test.config_flow", None)
|
mock_platform(hass, "test.config_flow", None)
|
||||||
@ -604,7 +605,7 @@ async def test_create_account(hass: HomeAssistant, client: TestClient) -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("enable_custom_integrations", "freezer")
|
@pytest.mark.usefixtures("freezer")
|
||||||
async def test_two_step_flow(hass: HomeAssistant, client: TestClient) -> None:
|
async def test_two_step_flow(hass: HomeAssistant, client: TestClient) -> None:
|
||||||
"""Test we can finish a two step flow."""
|
"""Test we can finish a two step flow."""
|
||||||
mock_integration(
|
mock_integration(
|
||||||
@ -835,9 +836,10 @@ async def test_get_progress_flow(hass: HomeAssistant, client: TestClient) -> Non
|
|||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
schema = OrderedDict()
|
schema = {
|
||||||
schema[vol.Required("username")] = str
|
vol.Required("username"): str,
|
||||||
schema[vol.Required("password")] = str
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
@ -873,9 +875,10 @@ async def test_get_progress_flow_unauth(
|
|||||||
|
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
schema = OrderedDict()
|
schema = {
|
||||||
schema[vol.Required("username")] = str
|
vol.Required("username"): str,
|
||||||
schema[vol.Required("password")] = str
|
vol.Required("password"): str,
|
||||||
|
}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
@ -907,11 +910,9 @@ async def test_options_flow(hass: HomeAssistant, client: TestClient) -> None:
|
|||||||
def async_get_options_flow(config_entry):
|
def async_get_options_flow(config_entry):
|
||||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
schema = OrderedDict()
|
|
||||||
schema[vol.Required("enabled")] = bool
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema(schema),
|
data_schema=vol.Schema({vol.Required("enabled"): bool}),
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -972,11 +973,9 @@ async def test_options_flow_unauth(
|
|||||||
def async_get_options_flow(config_entry):
|
def async_get_options_flow(config_entry):
|
||||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
schema = OrderedDict()
|
|
||||||
schema[vol.Required("enabled")] = bool
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=schema,
|
data_schema=vol.Schema({vol.Required("enabled"): bool}),
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1150,11 +1149,9 @@ async def test_subentry_flow(hass: HomeAssistant, client) -> None:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
schema = {}
|
|
||||||
schema[vol.Required("enabled")] = bool
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=schema,
|
data_schema=vol.Schema({vol.Required("enabled"): bool}),
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1206,11 +1203,9 @@ async def test_subentry_reconfigure_flow(hass: HomeAssistant, client) -> None:
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
async def async_step_reconfigure(self, user_input=None):
|
async def async_step_reconfigure(self, user_input=None):
|
||||||
schema = {}
|
|
||||||
schema[vol.Required("enabled")] = bool
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reconfigure",
|
step_id="reconfigure",
|
||||||
data_schema=schema,
|
data_schema=vol.Schema({vol.Required("enabled"): bool}),
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1277,11 +1272,9 @@ async def test_subentry_flow_unauth(
|
|||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
class SubentryFlowHandler(core_ce.ConfigSubentryFlow):
|
class SubentryFlowHandler(core_ce.ConfigSubentryFlow):
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
schema = {}
|
|
||||||
schema[vol.Required("enabled")] = bool
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=schema,
|
data_schema=vol.Schema({vol.Required("enabled"): bool}),
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2792,7 +2785,7 @@ async def test_flow_with_multiple_schema_errors_base(
|
|||||||
"ignore_translations",
|
"ignore_translations",
|
||||||
["component.test.config.abort.reconfigure_successful"],
|
["component.test.config.abort.reconfigure_successful"],
|
||||||
)
|
)
|
||||||
@pytest.mark.usefixtures("enable_custom_integrations", "freezer")
|
@pytest.mark.usefixtures("freezer")
|
||||||
async def test_supports_reconfigure(
|
async def test_supports_reconfigure(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
client: TestClient,
|
client: TestClient,
|
||||||
@ -2868,7 +2861,6 @@ async def test_supports_reconfigure(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("enable_custom_integrations")
|
|
||||||
async def test_does_not_support_reconfigure(
|
async def test_does_not_support_reconfigure(
|
||||||
hass: HomeAssistant, client: TestClient
|
hass: HomeAssistant, client: TestClient
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -2894,11 +2886,10 @@ async def test_does_not_support_reconfigure(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert resp.status == HTTPStatus.BAD_REQUEST
|
assert resp.status == HTTPStatus.BAD_REQUEST
|
||||||
response = await resp.text()
|
response = await resp.json()
|
||||||
assert (
|
assert response == {
|
||||||
response
|
"message": "Handler ConfigEntriesFlowManager doesn't support step reconfigure"
|
||||||
== '{"message":"Handler ConfigEntriesFlowManager doesn\'t support step reconfigure"}'
|
}
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_list_subentries(
|
async def test_list_subentries(
|
||||||
|
@ -512,6 +512,7 @@ async def test_remove_entry(
|
|||||||
assert len(entity_registry.entities) == 1
|
assert len(entity_registry.entities) == 1
|
||||||
entity_entry = list(entity_registry.entities.values())[0]
|
entity_entry = list(entity_registry.entities.values())[0]
|
||||||
assert entity_entry.config_entry_id == entry.entry_id
|
assert entity_entry.config_entry_id == entry.entry_id
|
||||||
|
assert entity_entry.config_subentry_id is None
|
||||||
|
|
||||||
# Remove entry
|
# Remove entry
|
||||||
result = await manager.async_remove("test2")
|
result = await manager.async_remove("test2")
|
||||||
@ -1271,7 +1272,7 @@ async def test_discovery_notification(
|
|||||||
notifications = async_get_persistent_notifications(hass)
|
notifications = async_get_persistent_notifications(hass)
|
||||||
assert "config_entry_discovery" not in notifications
|
assert "config_entry_discovery" not in notifications
|
||||||
|
|
||||||
# Start first discovery flow to assert that reconfigure notification fires
|
# Start first discovery flow to assert that discovery notification fires
|
||||||
flow1 = await hass.config_entries.flow.async_init(
|
flow1 = await hass.config_entries.flow.async_init(
|
||||||
"test", context={"source": config_entries.SOURCE_DISCOVERY}
|
"test", context={"source": config_entries.SOURCE_DISCOVERY}
|
||||||
)
|
)
|
||||||
@ -1994,7 +1995,7 @@ async def test_entry_subentry(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2050,7 +2051,7 @@ async def test_entry_subentry_non_string(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2092,7 +2093,7 @@ async def test_entry_subentry_no_context(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2139,7 +2140,7 @@ async def test_entry_subentry_duplicate(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2180,7 +2181,7 @@ async def test_entry_subentry_abort(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2227,7 +2228,7 @@ async def test_entry_subentry_deleted_config_entry(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -2270,7 +2271,7 @@ async def test_entry_subentry_unsupported_subentry_type(
|
|||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
class SubentryFlowHandler(data_entry_flow.FlowHandler):
|
class SubentryFlowHandler(config_entries.ConfigSubentryFlow):
|
||||||
"""Test subentry flow handler."""
|
"""Test subentry flow handler."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -7412,7 +7413,7 @@ async def test_get_reauth_entry(
|
|||||||
async def test_get_reconfigure_entry(
|
async def test_get_reconfigure_entry(
|
||||||
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
hass: HomeAssistant, manager: config_entries.ConfigEntries
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test _get_context_entry behavior."""
|
"""Test _get_reconfigure_entry behavior."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
title="test_title",
|
title="test_title",
|
||||||
domain="test",
|
domain="test",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user