From bf33e286d6f574595e097fda9098806e00ebb260 Mon Sep 17 00:00:00 2001 From: Yuxin Wang Date: Sun, 10 Aug 2025 08:32:25 -1000 Subject: [PATCH] Add recovery test logic for connection failure for APCUPSD (#150382) Co-authored-by: Joost Lekkerkerker --- .../components/apcupsd/quality_scale.yaml | 1 - tests/components/apcupsd/test_config_flow.py | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/apcupsd/quality_scale.yaml b/homeassistant/components/apcupsd/quality_scale.yaml index 6584a9b9461f..6c71cb16b5d1 100644 --- a/homeassistant/components/apcupsd/quality_scale.yaml +++ b/homeassistant/components/apcupsd/quality_scale.yaml @@ -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: diff --git a/tests/components/apcupsd/test_config_flow.py b/tests/components/apcupsd/test_config_flow.py index 768d6c71ff5b..9daa83373411 100644 --- a/tests/components/apcupsd/test_config_flow.py +++ b/tests/components/apcupsd/test_config_flow.py @@ -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"),