Ensure config entry is added to hass in reauth/reconfigure tests (#129315)

This commit is contained in:
epenet 2024-10-28 11:03:42 +01:00 committed by GitHub
parent 93c1245b0f
commit 2bec20ad76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -1064,6 +1064,8 @@ class MockConfigEntry(config_entries.ConfigEntry):
data: dict[str, Any] | None = None,
) -> ConfigFlowResult:
"""Start a reauthentication flow."""
if self.entry_id not in hass.config_entries._entries:
raise ValueError("Config entry must be added to hass to start reauth flow")
return await start_reauth_flow(hass, self, context, data)
async def start_reconfigure_flow(
@ -1073,6 +1075,10 @@ class MockConfigEntry(config_entries.ConfigEntry):
show_advanced_options: bool = False,
) -> ConfigFlowResult:
"""Start a reconfiguration flow."""
if self.entry_id not in hass.config_entries._entries:
raise ValueError(
"Config entry must be added to hass to start reconfiguration flow"
)
return await hass.config_entries.flow.async_init(
self.domain,
context={

View file

@ -57,6 +57,7 @@ async def test_reauth_authorization_error(
mock_devops_client: AsyncMock,
) -> None:
"""Test we show user form on Azure DevOps authorization error."""
mock_config_entry.add_to_hass(hass)
mock_devops_client.authorize.return_value = False
mock_devops_client.authorized = False
@ -108,6 +109,7 @@ async def test_reauth_connection_error(
mock_devops_client: AsyncMock,
) -> None:
"""Test we show user form on Azure DevOps connection error."""
mock_config_entry.add_to_hass(hass)
mock_devops_client.authorize.side_effect = aiohttp.ClientError
mock_devops_client.authorized = False