mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 09:58:07 -04:00
Split the Dune HD user flow init from its data (#180750)
This commit is contained in:
@@ -19,7 +19,15 @@ DUNEHD_STATE = {"protocol_version": "4", "player_state": "navigator"}
|
||||
async def test_user_invalid_host(hass: HomeAssistant) -> None:
|
||||
"""Test that errors are shown when the host is invalid."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: "invalid/host"}
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: "invalid/host"},
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_HOST: "invalid_host"}
|
||||
@@ -34,7 +42,15 @@ async def test_user_very_long_host(hass: HomeAssistant) -> None:
|
||||
"host_very_long_host_very_long_host"
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: long_host}
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: long_host},
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_HOST: "invalid_host"}
|
||||
@@ -44,7 +60,15 @@ async def test_user_cannot_connect(hass: HomeAssistant) -> None:
|
||||
"""Test that errors are shown when cannot connect to the host."""
|
||||
with patch("pdunehd.DuneHDPlayer.update_state", return_value={}):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_IP
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=CONFIG_IP,
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_HOST: "cannot_connect"}
|
||||
@@ -61,7 +85,15 @@ async def test_duplicate_error(hass: HomeAssistant) -> None:
|
||||
|
||||
with patch("pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_HOSTNAME
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=CONFIG_HOSTNAME,
|
||||
)
|
||||
|
||||
assert result["errors"] == {CONF_HOST: "already_configured"}
|
||||
@@ -74,7 +106,15 @@ async def test_create_entry(hass: HomeAssistant) -> None:
|
||||
patch("pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONFIG_HOSTNAME
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=CONFIG_HOSTNAME,
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
@@ -89,9 +129,15 @@ async def test_create_entry_with_ipv6_address(hass: HomeAssistant) -> None:
|
||||
patch("pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: "2001:db8::1428:57ab"},
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: "2001:db8::1428:57ab"},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
Reference in New Issue
Block a user