From c9c9bbb1d7d5514679d50bfd6c92965b5d127ecf Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 30 Aug 2026 13:07:05 +0200 Subject: [PATCH] Split the Pi-hole user flow init from its data (#180776) --- tests/components/pi_hole/test_config_flow.py | 64 +++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/tests/components/pi_hole/test_config_flow.py b/tests/components/pi_hole/test_config_flow.py index 6c856dcdc217..b3ffc35e8ef6 100644 --- a/tests/components/pi_hole/test_config_flow.py +++ b/tests/components/pi_hole/test_config_flow.py @@ -59,9 +59,15 @@ async def test_flow_user_with_api_key_v6(hass: HomeAssistant) -> None: # duplicated server result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data=CONFIG_FLOW_USER, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" @@ -109,9 +115,15 @@ async def test_flow_user_with_api_key_v5(hass: HomeAssistant) -> None: # duplicated server result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data=CONFIG_FLOW_USER, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" @@ -122,7 +134,15 @@ async def test_flow_user_invalid(hass: HomeAssistant) -> None: mocked_hole = _create_mocked_hole(raise_exception=True) with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_FLOW_USER + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" @@ -136,7 +156,15 @@ async def test_flow_user_invalid_v6(hass: HomeAssistant) -> None: ) with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_FLOW_USER + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" @@ -176,7 +204,15 @@ async def test_flow_user_invalid_host(hass: HomeAssistant) -> None: mocked_hole = _create_mocked_hole(api_version=6, wrong_host=True) with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_FLOW_USER + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "user" @@ -188,7 +224,15 @@ async def test_flow_error_response(hass: HomeAssistant) -> None: mocked_hole = _create_mocked_hole(api_version=5, ftl_error=True, has_data=False) with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_FLOW_USER + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=CONFIG_FLOW_USER, ) assert mocked_hole.instances[-1].data == FTL_ERROR assert result["type"] is FlowResultType.FORM