Add recovery test logic for connection failure for APCUPSD (#150382)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Yuxin Wang
2025-08-10 20:32:25 +02:00
committed by GitHub
co-authored by Joost Lekkerkerker
parent 6b83effc5f
commit bf33e286d6
2 changed files with 17 additions and 2 deletions
@@ -11,7 +11,6 @@ rules:
status: done
comment: |
Consider looking into making a `mock_setup_entry` fixture that just automatically do this.
`test_config_flow_cannot_connect`: Needs to end in CREATE_ENTRY to test that its able to recover.
config-flow: done
dependency-transparency: done
docs-actions:
+17 -1
View File
@@ -229,7 +229,7 @@ async def test_reconfigure_flow_works(hass: HomeAssistant) -> None:
async def test_reconfigure_flow_cannot_connect(hass: HomeAssistant) -> None:
"""Test reconfiguration with connection error."""
"""Test reconfiguration with connection error and recovery."""
mock_entry = MockConfigEntry(
version=1,
domain=DOMAIN,
@@ -257,6 +257,22 @@ async def test_reconfigure_flow_cannot_connect(hass: HomeAssistant) -> None:
assert result["type"] is FlowResultType.FORM
assert result["errors"]["base"] == "cannot_connect"
# Test recovery by fixing the connection issue.
with (
patch(
"homeassistant.components.apcupsd.coordinator.aioapcaccess.request_status",
return_value=MOCK_STATUS,
),
_patch_setup(),
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=new_conf_data
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert mock_entry.data == new_conf_data
@pytest.mark.parametrize(
("unique_id_before", "unique_id_after"),