Align config flow reconfigure step test helper with frontend (#127329)
* Align config flow reconfigure step with frontend * Update common.py * Update common.py * Adjust * Adjust * Fix test * Adjust
This commit is contained in:
parent
94df3e931a
commit
7d3d693fe8
3 changed files with 14 additions and 63 deletions
|
@ -1069,8 +1069,8 @@ class MockConfigEntry(config_entries.ConfigEntry):
|
|||
async def start_reconfigure_flow(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
context: dict[str, Any] | None = None,
|
||||
data: dict[str, Any] | None = None,
|
||||
*,
|
||||
show_advanced_options: bool = False,
|
||||
) -> ConfigFlowResult:
|
||||
"""Start a reconfiguration flow."""
|
||||
return await hass.config_entries.flow.async_init(
|
||||
|
@ -1078,11 +1078,8 @@ class MockConfigEntry(config_entries.ConfigEntry):
|
|||
context={
|
||||
"source": config_entries.SOURCE_RECONFIGURE,
|
||||
"entry_id": self.entry_id,
|
||||
"title_placeholders": {"name": self.title},
|
||||
"unique_id": self.unique_id,
|
||||
}
|
||||
| (context or {}),
|
||||
data=self.data | (data or {}),
|
||||
"show_advanced_options": show_advanced_options,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -454,7 +454,7 @@ async def test_reconfigure_successful(
|
|||
|
||||
result = await mock_config.start_reconfigure_flow(
|
||||
hass,
|
||||
context={"show_advanced_options": show_advanced_options},
|
||||
show_advanced_options=show_advanced_options,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
|
|
@ -6410,7 +6410,7 @@ async def test_get_reauth_entry(
|
|||
"""Test reauth step."""
|
||||
return await self._async_step_confirm()
|
||||
|
||||
async def async_step_reconfigure(self, entry_data):
|
||||
async def async_step_reconfigure(self, user_input=None):
|
||||
"""Test reauth step."""
|
||||
return await self._async_step_confirm()
|
||||
|
||||
|
@ -6482,7 +6482,7 @@ async def test_get_reconfigure_entry(
|
|||
"""Test reauth step."""
|
||||
return await self._async_step_confirm()
|
||||
|
||||
async def async_step_reconfigure(self, entry_data):
|
||||
async def async_step_reconfigure(self, user_input=None):
|
||||
"""Test reauth step."""
|
||||
return await self._async_step_confirm()
|
||||
|
||||
|
@ -6514,10 +6514,14 @@ async def test_get_reconfigure_entry(
|
|||
result = await entry.start_reconfigure_flow(hass)
|
||||
assert result["reason"] == "Found entry test_title: 01J915Q6T9F6G5V0QJX6HBC94T"
|
||||
|
||||
# A reconfigure flow finds the config entry
|
||||
# The entry_id no longer exists
|
||||
with mock_config_flow("test", TestFlow):
|
||||
result = await entry.start_reconfigure_flow(
|
||||
hass, context={"entry_id": "01JRemoved"}
|
||||
result = await manager.flow.async_init(
|
||||
"test",
|
||||
context={
|
||||
"source": config_entries.SOURCE_RECONFIGURE,
|
||||
"entry_id": "01JRemoved",
|
||||
},
|
||||
)
|
||||
assert result["reason"] == "Entry not found: 01JRemoved"
|
||||
|
||||
|
@ -6586,53 +6590,3 @@ async def test_reauth_helper_alignment(
|
|||
# Ensure context and init data are aligned
|
||||
assert helper_flow_context == reauth_flow_context
|
||||
assert helper_flow_init_data == reauth_flow_init_data
|
||||
|
||||
|
||||
async def test_reconfigure_helper_alignment(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
) -> None:
|
||||
"""Test `start_reconfigure_flow` helper alignment.
|
||||
|
||||
It should be aligned with `ConfigEntry._async_init_reconfigure`.
|
||||
"""
|
||||
entry = MockConfigEntry(
|
||||
title="test_title",
|
||||
domain="test",
|
||||
entry_id="01J915Q6T9F6G5V0QJX6HBC94T",
|
||||
data={"host": "any", "port": 123},
|
||||
unique_id=None,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
mock_integration(hass, MockModule("test"))
|
||||
mock_platform(hass, "test.config_flow", None)
|
||||
|
||||
# Check context via auto-generated reconfigure
|
||||
entry.async_start_reconfigure(hass)
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
|
||||
reconfigure_flow_context = flows[0]["context"]
|
||||
reconfigure_flow_init_data = hass.config_entries.flow._progress[
|
||||
flows[0]["flow_id"]
|
||||
].init_data
|
||||
|
||||
# Clear to make way for `start_reauth_flow` helper
|
||||
manager.flow.async_abort(flows[0]["flow_id"])
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 0
|
||||
|
||||
# Check context via `start_reconfigure_flow` helper
|
||||
await entry.start_reconfigure_flow(hass)
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
helper_flow_context = flows[0]["context"]
|
||||
helper_flow_init_data = hass.config_entries.flow._progress[
|
||||
flows[0]["flow_id"]
|
||||
].init_data
|
||||
|
||||
# Ensure context and init data are aligned
|
||||
assert helper_flow_context == reconfigure_flow_context
|
||||
assert helper_flow_init_data == reconfigure_flow_init_data
|
||||
|
|
Loading…
Add table
Reference in a new issue