1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

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:
epenet
2024-10-03 10:21:23 +02:00
committed by GitHub
parent 94df3e931a
commit 7d3d693fe8
3 changed files with 14 additions and 63 deletions

View File

@@ -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