Use start_reauth_flow helper in ezviz and netatmo tests (#127100)

* Use start_reauth_flow helper in netatmo tests

* Use start_reauth_flow helper in ezviz tests
This commit is contained in:
epenet 2024-09-30 16:38:34 +02:00 committed by GitHub
parent 636cba5d6b
commit 86a95013b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 32 deletions

View file

@ -1063,21 +1063,31 @@ class MockConfigEntry(config_entries.ConfigEntry):
context: dict[str, Any] | None = None,
data: dict[str, Any] | None = None,
) -> ConfigFlowResult:
"""Start a reauthentication flow for a config entry.
"""Start a reauthentication flow."""
return await start_reauth_flow(hass, self, context, data)
This helper method should be aligned with `ConfigEntry._async_init_reauth`.
"""
return await hass.config_entries.flow.async_init(
self.domain,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": self.entry_id,
"title_placeholders": {"name": self.title},
"unique_id": self.unique_id,
}
| (context or {}),
data=self.data | (data or {}),
)
async def start_reauth_flow(
hass: HomeAssistant,
entry: ConfigEntry,
context: dict[str, Any] | None = None,
data: dict[str, Any] | None = None,
) -> ConfigFlowResult:
"""Start a reauthentication flow for a config entry.
This helper method should be aligned with `ConfigEntry._async_init_reauth`.
"""
return await hass.config_entries.flow.async_init(
entry.domain,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": entry.entry_id,
"title_placeholders": {"name": entry.title},
"unique_id": entry.unique_id,
}
| (context or {}),
data=entry.data | (data or {}),
)
def patch_yaml_files(files_dict, endswith=True):

View file

@ -20,11 +20,7 @@ from homeassistant.components.ezviz.const import (
DEFAULT_TIMEOUT,
DOMAIN,
)
from homeassistant.config_entries import (
SOURCE_INTEGRATION_DISCOVERY,
SOURCE_REAUTH,
SOURCE_USER,
)
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, SOURCE_USER
from homeassistant.const import (
CONF_CUSTOMIZE,
CONF_IP_ADDRESS,
@ -45,6 +41,8 @@ from . import (
patch_async_setup_entry,
)
from tests.common import MockConfigEntry, start_reauth_flow
@pytest.mark.usefixtures("ezviz_config_flow")
async def test_user_form(hass: HomeAssistant) -> None:
@ -134,9 +132,8 @@ async def test_async_step_reauth(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
)
new_entry = hass.config_entries.async_entries(DOMAIN)[0]
result = await start_reauth_flow(hass, new_entry)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
assert result["errors"] == {}
@ -182,9 +179,10 @@ async def test_step_discovery_abort_if_cloud_account_missing(
async def test_step_reauth_abort_if_cloud_account_missing(hass: HomeAssistant) -> None:
"""Test reauth and confirm step, abort if cloud account was removed."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
)
entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT_VALIDATE)
entry.add_to_hass(hass)
result = await entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "ezviz_cloud_account_missing"
@ -562,9 +560,8 @@ async def test_async_step_reauth_exception(
assert len(mock_setup_entry.mock_calls) == 1
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
)
new_entry = hass.config_entries.async_entries(DOMAIN)[0]
result = await start_reauth_flow(hass, new_entry)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
assert result["errors"] == {}

View file

@ -23,7 +23,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
from .conftest import CLIENT_ID
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, start_reauth_flow
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
@ -282,9 +282,7 @@ async def test_reauth(
assert len(mock_setup.mock_calls) == 1
# Should show form
result = await hass.config_entries.flow.async_init(
"netatmo", context={"source": config_entries.SOURCE_REAUTH}
)
result = await start_reauth_flow(hass, new_entry)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"