mirror of
https://github.com/home-assistant/core.git
synced 2026-10-09 07:48:22 -04:00
Split user flow init and data submission in ridwell config flow tests (#184170)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Test the Ridwell config flow."""
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aioridwell.errors import InvalidCredentialsError, RidwellError
|
||||
@@ -21,14 +22,18 @@ from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("get_client_response", "errors"),
|
||||
("side_effect", "errors"),
|
||||
[
|
||||
(AsyncMock(side_effect=InvalidCredentialsError), {"base": "invalid_auth"}),
|
||||
(AsyncMock(side_effect=RidwellError), {"base": "unknown"}),
|
||||
(InvalidCredentialsError, "invalid_auth"),
|
||||
(RidwellError, "unknown"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_aioridwell")
|
||||
async def test_create_entry(
|
||||
hass: HomeAssistant, config, errors, get_client_response, mock_aioridwell
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
errors: str,
|
||||
side_effect: type[Exception],
|
||||
) -> None:
|
||||
"""Test creating an entry."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -36,18 +41,19 @@ async def test_create_entry(
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
# Test errors that can arise:
|
||||
with patch(
|
||||
"homeassistant.components.ridwell.config_flow.async_get_client",
|
||||
get_client_response,
|
||||
AsyncMock(side_effect=side_effect),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == errors
|
||||
assert result["errors"] == {"base": errors}
|
||||
|
||||
# Test that we can recover and finish the flow after errors occur:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
@@ -61,18 +67,25 @@ async def test_create_entry(
|
||||
}
|
||||
|
||||
|
||||
async def test_duplicate_error(hass: HomeAssistant, config, setup_config_entry) -> None:
|
||||
@pytest.mark.usefixtures("setup_config_entry")
|
||||
async def test_duplicate_error(hass: HomeAssistant, config: dict[str, Any]) -> None:
|
||||
"""Test that errors are shown when duplicate entries are added."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=config
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=config
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_step_reauth(
|
||||
hass: HomeAssistant, config, config_entry: MockConfigEntry, setup_config_entry
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("setup_config_entry")
|
||||
async def test_step_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
|
||||
"""Test a full reauth flow."""
|
||||
result = await config_entry.start_reauth_flow(hass)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
@@ -106,13 +119,17 @@ async def test_option_flow_event_title(
|
||||
assert result["data"][CONF_CALENDAR_TITLE] == CALENDAR_TITLE_ROTATING
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_aioridwell")
|
||||
async def test_successful_config_flow(
|
||||
hass: HomeAssistant, config, mock_aioridwell
|
||||
hass: HomeAssistant, config: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test the happy path of a successful config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert not result["errors"]
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
|
||||
|
||||
Reference in New Issue
Block a user