From 70aacfce9867a53beef02324d8cdd9d75e1fa577 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 9 Apr 2025 16:47:04 +0200 Subject: [PATCH] Improve tests of clean up when reauth flow aborts (#142592) --- tests/test_config_entries.py | 40 +++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 2d9d18a067d..8f1591cec3b 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -1367,11 +1367,44 @@ async def test_async_forward_entry_setup_deprecated( ) in caplog.text -async def test_reauth_issue( +async def test_reauth_issue_flow_returns_abort( hass: HomeAssistant, manager: config_entries.ConfigEntries, issue_registry: ir.IssueRegistry, ) -> None: + """Test that we create/delete an issue when source is reauth. + + In this test, the reauth flow returns abort. + """ + issue = await _test_reauth_issue(hass, manager, issue_registry) + + result = await manager.flow.async_configure(issue.data["flow_id"], {}) + assert result["type"] == FlowResultType.ABORT + assert len(issue_registry.issues) == 0 + + +async def test_reauth_issue_flow_aborted( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + issue_registry: ir.IssueRegistry, +) -> None: + """Test that we create/delete an issue when source is reauth. + + In this test, the reauth flow is aborted. + """ + issue = await _test_reauth_issue(hass, manager, issue_registry) + + manager.flow.async_abort(issue.data["flow_id"]) + # This can be considered a bug, we should make sure the issue is always + # removed when the reauth flow is aborted. + assert len(issue_registry.issues) == 1 + + +async def _test_reauth_issue( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + issue_registry: ir.IssueRegistry, +) -> ir.IssueEntry: """Test that we create/delete an issue when source is reauth.""" assert len(issue_registry.issues) == 0 @@ -1407,10 +1440,7 @@ async def test_reauth_issue( translation_key="config_entry_reauth", translation_placeholders={"name": "test_title"}, ) - - result = await hass.config_entries.flow.async_configure(issue.data["flow_id"], {}) - assert result["type"] == FlowResultType.ABORT - assert len(issue_registry.issues) == 0 + return issue async def test_loading_default_config(hass: HomeAssistant) -> None: