From 0a5b5a646659f7eeac8f45e16d8974bf81fd6dd8 Mon Sep 17 00:00:00 2001 From: Manu Date: Sun, 4 Oct 2026 09:02:24 +0200 Subject: [PATCH] Split user flow init and data submission in ridwell config flow tests (#184170) --- tests/components/ridwell/test_config_flow.py | 41 ++++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/tests/components/ridwell/test_config_flow.py b/tests/components/ridwell/test_config_flow.py index 8658decc5765..99ff7953cf55 100644 --- a/tests/components/ridwell/test_config_flow.py +++ b/tests/components/ridwell/test_config_flow.py @@ -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