mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
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:
parent
636cba5d6b
commit
86a95013b6
@ -1063,21 +1063,31 @@ class MockConfigEntry(config_entries.ConfigEntry):
|
|||||||
context: dict[str, Any] | None = None,
|
context: dict[str, Any] | None = None,
|
||||||
data: dict[str, Any] | None = None,
|
data: dict[str, Any] | None = None,
|
||||||
) -> ConfigFlowResult:
|
) -> 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`.
|
|
||||||
"""
|
async def start_reauth_flow(
|
||||||
return await hass.config_entries.flow.async_init(
|
hass: HomeAssistant,
|
||||||
self.domain,
|
entry: ConfigEntry,
|
||||||
context={
|
context: dict[str, Any] | None = None,
|
||||||
"source": config_entries.SOURCE_REAUTH,
|
data: dict[str, Any] | None = None,
|
||||||
"entry_id": self.entry_id,
|
) -> ConfigFlowResult:
|
||||||
"title_placeholders": {"name": self.title},
|
"""Start a reauthentication flow for a config entry.
|
||||||
"unique_id": self.unique_id,
|
|
||||||
}
|
This helper method should be aligned with `ConfigEntry._async_init_reauth`.
|
||||||
| (context or {}),
|
"""
|
||||||
data=self.data | (data or {}),
|
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):
|
def patch_yaml_files(files_dict, endswith=True):
|
||||||
|
@ -20,11 +20,7 @@ from homeassistant.components.ezviz.const import (
|
|||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, SOURCE_USER
|
||||||
SOURCE_INTEGRATION_DISCOVERY,
|
|
||||||
SOURCE_REAUTH,
|
|
||||||
SOURCE_USER,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CUSTOMIZE,
|
CONF_CUSTOMIZE,
|
||||||
CONF_IP_ADDRESS,
|
CONF_IP_ADDRESS,
|
||||||
@ -45,6 +41,8 @@ from . import (
|
|||||||
patch_async_setup_entry,
|
patch_async_setup_entry,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry, start_reauth_flow
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("ezviz_config_flow")
|
@pytest.mark.usefixtures("ezviz_config_flow")
|
||||||
async def test_user_form(hass: HomeAssistant) -> None:
|
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
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
new_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
|
result = await start_reauth_flow(hass, new_entry)
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["errors"] == {}
|
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:
|
async def test_step_reauth_abort_if_cloud_account_missing(hass: HomeAssistant) -> None:
|
||||||
"""Test reauth and confirm step, abort if cloud account was removed."""
|
"""Test reauth and confirm step, abort if cloud account was removed."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
entry = MockConfigEntry(domain=DOMAIN, data=USER_INPUT_VALIDATE)
|
||||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
|
entry.add_to_hass(hass)
|
||||||
)
|
|
||||||
|
result = await entry.start_reauth_flow(hass)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "ezviz_cloud_account_missing"
|
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
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
new_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=USER_INPUT_VALIDATE
|
result = await start_reauth_flow(hass, new_entry)
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
@ -23,7 +23,7 @@ from homeassistant.helpers import config_entry_oauth2_flow
|
|||||||
|
|
||||||
from .conftest import CLIENT_ID
|
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.test_util.aiohttp import AiohttpClientMocker
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
@ -282,9 +282,7 @@ async def test_reauth(
|
|||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
# Should show form
|
# Should show form
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await start_reauth_flow(hass, new_entry)
|
||||||
"netatmo", context={"source": config_entries.SOURCE_REAUTH}
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user