Improve tests of clean up when reauth flow aborts (#142592)

This commit is contained in:
Erik Montnemery 2025-04-09 16:47:04 +02:00 committed by GitHub
parent 8625a36d1d
commit 70aacfce98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: