Increase Squeezebox config_flow test coverage to 100% (#133484)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
pull/133502/head
peteS-UK 2024-12-18 17:22:22 +00:00 committed by GitHub
parent a6089b497a
commit 920de90603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 61 additions and 0 deletions

View File

@ -166,6 +166,67 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
assert result["errors"] == {"base": "invalid_auth"}
async def test_form_validate_exception(hass: HomeAssistant) -> None:
"""Test we handle exception."""
with (
patch(
"pysqueezebox.Server.async_query",
return_value={"uuid": UUID},
),
patch(
"homeassistant.components.squeezebox.async_setup_entry",
return_value=True,
),
patch(
"homeassistant.components.squeezebox.config_flow.async_discover",
mock_discover,
),
):
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"] == "edit"
with patch(
"homeassistant.components.squeezebox.config_flow.Server.async_query",
side_effect=Exception,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_HOST: HOST,
CONF_PORT: PORT,
CONF_USERNAME: "",
CONF_PASSWORD: "",
},
)
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": "unknown"}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_HOST: HOST,
CONF_PORT: PORT,
CONF_USERNAME: "",
CONF_PASSWORD: "",
CONF_HTTPS: False,
},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == HOST
assert result["data"] == {
CONF_HOST: HOST,
CONF_PORT: PORT,
CONF_USERNAME: "",
CONF_PASSWORD: "",
CONF_HTTPS: False,
}
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(