diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 24b775ccd90..9b5ff3c9f3e 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -1,6 +1,5 @@ """Test config entries API.""" -from collections import OrderedDict from collections.abc import Generator from http import HTTPStatus from typing import Any @@ -411,9 +410,10 @@ async def test_initialize_flow(hass: HomeAssistant, client: TestClient) -> None: class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("username")] = str - schema[vol.Required("password")] = str + schema = { + vol.Required("username"): str, + vol.Required("password"): str, + } return self.async_show_form( step_id="user", @@ -493,13 +493,14 @@ async def test_initialize_flow_unauth( class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("username")] = str - schema[vol.Required("password")] = str + schema = { + vol.Required("username"): str, + vol.Required("password"): str, + } return self.async_show_form( step_id="user", - data_schema=schema, + data_schema=vol.Schema(schema), description_placeholders={"url": "https://example.com"}, 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: """Test a flow that creates an account.""" 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: """Test we can finish a two step flow.""" mock_integration( @@ -835,9 +836,10 @@ async def test_get_progress_flow(hass: HomeAssistant, client: TestClient) -> Non class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("username")] = str - schema[vol.Required("password")] = str + schema = { + vol.Required("username"): str, + vol.Required("password"): str, + } return self.async_show_form( step_id="user", @@ -873,9 +875,10 @@ async def test_get_progress_flow_unauth( class TestFlow(core_ce.ConfigFlow): async def async_step_user(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("username")] = str - schema[vol.Required("password")] = str + schema = { + vol.Required("username"): str, + vol.Required("password"): str, + } return self.async_show_form( step_id="user", @@ -907,11 +910,9 @@ async def test_options_flow(hass: HomeAssistant, client: TestClient) -> None: def async_get_options_flow(config_entry): class OptionsFlowHandler(data_entry_flow.FlowHandler): async def async_step_init(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("enabled")] = bool return self.async_show_form( 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"}, ) @@ -972,11 +973,9 @@ async def test_options_flow_unauth( def async_get_options_flow(config_entry): class OptionsFlowHandler(data_entry_flow.FlowHandler): async def async_step_init(self, user_input=None): - schema = OrderedDict() - schema[vol.Required("enabled")] = bool return self.async_show_form( step_id="user", - data_schema=schema, + data_schema=vol.Schema({vol.Required("enabled"): bool}), description_placeholders={"enabled": "Set to true to be true"}, ) @@ -1150,11 +1149,9 @@ async def test_subentry_flow(hass: HomeAssistant, client) -> None: raise NotImplementedError async def async_step_user(self, user_input=None): - schema = {} - schema[vol.Required("enabled")] = bool return self.async_show_form( step_id="user", - data_schema=schema, + data_schema=vol.Schema({vol.Required("enabled"): bool}), 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 async def async_step_reconfigure(self, user_input=None): - schema = {} - schema[vol.Required("enabled")] = bool return self.async_show_form( step_id="reconfigure", - data_schema=schema, + data_schema=vol.Schema({vol.Required("enabled"): bool}), 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 SubentryFlowHandler(core_ce.ConfigSubentryFlow): async def async_step_init(self, user_input=None): - schema = {} - schema[vol.Required("enabled")] = bool return self.async_show_form( step_id="user", - data_schema=schema, + data_schema=vol.Schema({vol.Required("enabled"): bool}), description_placeholders={"enabled": "Set to true to be true"}, ) @@ -2792,7 +2785,7 @@ async def test_flow_with_multiple_schema_errors_base( "ignore_translations", ["component.test.config.abort.reconfigure_successful"], ) -@pytest.mark.usefixtures("enable_custom_integrations", "freezer") +@pytest.mark.usefixtures("freezer") async def test_supports_reconfigure( hass: HomeAssistant, client: TestClient, @@ -2868,7 +2861,6 @@ async def test_supports_reconfigure( } -@pytest.mark.usefixtures("enable_custom_integrations") async def test_does_not_support_reconfigure( hass: HomeAssistant, client: TestClient ) -> None: @@ -2894,11 +2886,10 @@ async def test_does_not_support_reconfigure( ) assert resp.status == HTTPStatus.BAD_REQUEST - response = await resp.text() - assert ( - response - == '{"message":"Handler ConfigEntriesFlowManager doesn\'t support step reconfigure"}' - ) + response = await resp.json() + assert response == { + "message": "Handler ConfigEntriesFlowManager doesn't support step reconfigure" + } async def test_list_subentries( diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 105b5273918..a5cf3ad3a1a 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -512,6 +512,7 @@ async def test_remove_entry( assert len(entity_registry.entities) == 1 entity_entry = list(entity_registry.entities.values())[0] assert entity_entry.config_entry_id == entry.entry_id + assert entity_entry.config_subentry_id is None # Remove entry result = await manager.async_remove("test2") @@ -1271,7 +1272,7 @@ async def test_discovery_notification( notifications = async_get_persistent_notifications(hass) 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( "test", context={"source": config_entries.SOURCE_DISCOVERY} ) @@ -1994,7 +1995,7 @@ async def test_entry_subentry( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2050,7 +2051,7 @@ async def test_entry_subentry_non_string( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2092,7 +2093,7 @@ async def test_entry_subentry_no_context( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2139,7 +2140,7 @@ async def test_entry_subentry_duplicate( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2180,7 +2181,7 @@ async def test_entry_subentry_abort( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2227,7 +2228,7 @@ async def test_entry_subentry_deleted_config_entry( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -2270,7 +2271,7 @@ async def test_entry_subentry_unsupported_subentry_type( class TestFlow(config_entries.ConfigFlow): """Test flow.""" - class SubentryFlowHandler(data_entry_flow.FlowHandler): + class SubentryFlowHandler(config_entries.ConfigSubentryFlow): """Test subentry flow handler.""" @classmethod @@ -7412,7 +7413,7 @@ async def test_get_reauth_entry( async def test_get_reconfigure_entry( hass: HomeAssistant, manager: config_entries.ConfigEntries ) -> None: - """Test _get_context_entry behavior.""" + """Test _get_reconfigure_entry behavior.""" entry = MockConfigEntry( title="test_title", domain="test",