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

Add test helper for starting reconfiguration flow (#127154)

This commit is contained in:
epenet
2024-10-01 12:18:07 +02:00
committed by GitHub
parent f02f0eae59
commit b95dfe2b00
3 changed files with 70 additions and 8 deletions

View File

@@ -6440,3 +6440,53 @@ 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