Split user flow init and data submission in homematicip_cloud config flow tests (#179097)

This commit is contained in:
Christian Lackas
2026-08-14 12:18:00 +02:00
committed by GitHub
parent fdeb5409a4
commit 91598daedb
@@ -23,6 +23,13 @@ IMPORT_CONFIG = {HMIPC_HAPID: "ABC123", HMIPC_AUTHTOKEN: "123", HMIPC_NAME: "hmi
async def test_flow_works(hass: HomeAssistant, simple_mock_home) -> None:
"""Test config flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
with (
patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
@@ -33,10 +40,8 @@ async def test_flow_works(hass: HomeAssistant, simple_mock_home) -> None:
return_value=True,
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=DEFAULT_CONFIG,
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=DEFAULT_CONFIG
)
assert result["type"] is FlowResultType.FORM
@@ -79,22 +84,35 @@ async def test_flow_works(hass: HomeAssistant, simple_mock_home) -> None:
async def test_flow_init_connection_error(hass: HomeAssistant) -> None:
"""Test config flow with accesspoint connection error."""
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_setup",
return_value=False,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=DEFAULT_CONFIG,
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_setup",
return_value=False,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=DEFAULT_CONFIG
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
assert result["errors"] == {"base": "invalid_sgtin_or_pin"}
async def test_flow_link_connection_error(hass: HomeAssistant) -> None:
"""Test config flow client registration connection error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
with (
patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
@@ -109,10 +127,8 @@ async def test_flow_link_connection_error(hass: HomeAssistant) -> None:
return_value=False,
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=DEFAULT_CONFIG,
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=DEFAULT_CONFIG
)
assert result["type"] is FlowResultType.ABORT
@@ -121,6 +137,13 @@ async def test_flow_link_connection_error(hass: HomeAssistant) -> None:
async def test_flow_link_press_button(hass: HomeAssistant) -> None:
"""Test config flow ask for pressing the blue button."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
with (
patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
@@ -131,10 +154,8 @@ async def test_flow_link_press_button(hass: HomeAssistant) -> None:
return_value=True,
),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=DEFAULT_CONFIG,
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=DEFAULT_CONFIG
)
assert result["type"] is FlowResultType.FORM
@@ -155,14 +176,20 @@ async def test_init_flow_show_form(hass: HomeAssistant) -> None:
async def test_init_already_configured(hass: HomeAssistant) -> None:
"""Test accesspoint is already configured."""
MockConfigEntry(domain=DOMAIN, unique_id="ABC123").add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
return_value=True,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=DEFAULT_CONFIG,
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=DEFAULT_CONFIG
)
assert result["type"] is FlowResultType.ABORT