Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Whirlpool tests into a parameterized test #136490

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 13 additions & 51 deletions tests/components/whirlpool/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ async def test_form_invalid_auth(
assert result2["errors"] == {"base": "invalid_auth"}


async def test_form_cannot_connect(
@pytest.mark.parametrize(
("exception", "expected_error"),
[
(aiohttp.ClientConnectionError, "cannot_connect"),
(TimeoutError, "cannot_connect"),
(Exception, "unknown"),
],
)
async def test_form_auth_error(
exception: Exception,
expected_error: str,
hass: HomeAssistant,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have hass as the first parameter

region,
brand,
Expand All @@ -81,7 +91,7 @@ async def test_form_cannot_connect(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

mock_auth_api.return_value.do_auth.side_effect = aiohttp.ClientConnectionError
mock_auth_api.return_value.do_auth.side_effect = exception
result2 = await hass.config_entries.flow.async_configure(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reuse result

result["flow_id"],
CONFIG_INPUT
Expand All @@ -91,55 +101,7 @@ async def test_form_cannot_connect(
},
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"base": "cannot_connect"}


async def test_form_auth_timeout(
hass: HomeAssistant,
region,
brand,
mock_auth_api: MagicMock,
) -> None:
"""Test we handle auth timeout error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

mock_auth_api.return_value.do_auth.side_effect = TimeoutError
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
CONFIG_INPUT
| {
"region": region[0],
"brand": brand[0],
},
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"base": "cannot_connect"}


async def test_form_generic_auth_exception(
hass: HomeAssistant,
region,
brand,
mock_auth_api: MagicMock,
) -> None:
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)

mock_auth_api.return_value.do_auth.side_effect = Exception
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
CONFIG_INPUT
| {
"region": region[0],
"brand": brand[0],
},
)
assert result2["type"] is FlowResultType.FORM
assert result2["errors"] == {"base": "unknown"}
assert result2["errors"] == {"base": expected_error}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also directly make this test finish in a CREATE ENTRY to also test that it's able to recover



@pytest.mark.usefixtures("mock_auth_api", "mock_appliances_manager_api")
Expand Down