Use FlowResultType enum in config flow tests A-M (#114681)
This commit is contained in:
parent
a767530970
commit
b9281327c4
111 changed files with 997 additions and 961 deletions
|
@ -13,6 +13,7 @@ from homeassistant.components import zeroconf
|
|||
from homeassistant.components.hue import config_flow, const
|
||||
from homeassistant.components.hue.errors import CannotConnect
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
@ -61,14 +62,14 @@ async def test_flow_works(hass: HomeAssistant) -> None:
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={"id": disc_bridge.id}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
flow = next(
|
||||
|
@ -83,7 +84,7 @@ async def test_flow_works(hass: HomeAssistant) -> None:
|
|||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Hue Bridge aabbccddeeff"
|
||||
assert result["data"] == {
|
||||
"host": "1.2.3.4",
|
||||
|
@ -108,14 +109,14 @@ async def test_manual_flow_works(hass: HomeAssistant) -> None:
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input={"id": "manual"}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "manual"
|
||||
|
||||
with patch.object(config_flow, "discover_bridge", return_value=disc_bridge):
|
||||
|
@ -123,7 +124,7 @@ async def test_manual_flow_works(hass: HomeAssistant) -> None:
|
|||
result["flow_id"], {"host": "2.2.2.2"}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
with (
|
||||
|
@ -132,7 +133,7 @@ async def test_manual_flow_works(hass: HomeAssistant) -> None:
|
|||
):
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == f"Hue Bridge {disc_bridge.id}"
|
||||
assert result["data"] == {
|
||||
"host": "2.2.2.2",
|
||||
|
@ -159,14 +160,14 @@ async def test_manual_flow_bridge_exist(hass: HomeAssistant) -> None:
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "manual"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"host": "2.2.2.2"}
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
|
@ -179,7 +180,7 @@ async def test_manual_flow_no_discovered_bridges(
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "manual"
|
||||
|
||||
|
||||
|
@ -199,7 +200,7 @@ async def test_flow_all_discovered_bridges_exist(
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "manual"
|
||||
|
||||
|
||||
|
@ -219,7 +220,7 @@ async def test_flow_bridges_discovered(
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
|
@ -243,7 +244,7 @@ async def test_flow_two_bridges_discovered_one_new(
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
assert result["data_schema"]({"id": "beer"})
|
||||
assert result["data_schema"]({"id": "manual"})
|
||||
|
@ -261,7 +262,7 @@ async def test_flow_timeout_discovery(hass: HomeAssistant) -> None:
|
|||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "manual"
|
||||
|
||||
|
||||
|
@ -285,7 +286,7 @@ async def test_flow_link_unknown_error(hass: HomeAssistant) -> None:
|
|||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
assert result["errors"] == {"base": "linking"}
|
||||
|
||||
|
@ -310,7 +311,7 @@ async def test_flow_link_button_not_pressed(hass: HomeAssistant) -> None:
|
|||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
assert result["errors"] == {"base": "register_failed"}
|
||||
|
||||
|
@ -335,7 +336,7 @@ async def test_flow_link_cannot_connect(hass: HomeAssistant) -> None:
|
|||
result["flow_id"], user_input={}
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
|
@ -350,7 +351,7 @@ async def test_import_with_no_config(
|
|||
data={"host": "0.0.0.0"},
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
|
||||
|
@ -385,7 +386,7 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(
|
|||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
with (
|
||||
|
@ -397,7 +398,7 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(
|
|||
):
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "Hue Bridge id-1234"
|
||||
assert result["data"] == {
|
||||
"host": "2.2.2.2",
|
||||
|
@ -431,7 +432,7 @@ async def test_bridge_homekit(
|
|||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
flow = next(
|
||||
|
@ -454,7 +455,7 @@ async def test_bridge_import_already_configured(hass: HomeAssistant) -> None:
|
|||
data={"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
|
@ -481,7 +482,7 @@ async def test_bridge_homekit_already_configured(
|
|||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
|
@ -496,7 +497,7 @@ async def test_options_flow_v1(hass: HomeAssistant) -> None:
|
|||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
schema = result["data_schema"].schema
|
||||
assert (
|
||||
|
@ -516,7 +517,7 @@ async def test_options_flow_v1(hass: HomeAssistant) -> None:
|
|||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
const.CONF_ALLOW_HUE_GROUPS: True,
|
||||
const.CONF_ALLOW_UNREACHABLE: True,
|
||||
|
@ -550,7 +551,7 @@ async def test_options_flow_v2(
|
|||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
schema = result["data_schema"].schema
|
||||
assert _get_schema_default(schema, const.CONF_IGNORE_AVAILABILITY) == []
|
||||
|
@ -560,7 +561,7 @@ async def test_options_flow_v2(
|
|||
user_input={const.CONF_IGNORE_AVAILABILITY: [mock_dev_id]},
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
const.CONF_IGNORE_AVAILABILITY: [mock_dev_id],
|
||||
}
|
||||
|
@ -589,7 +590,7 @@ async def test_bridge_zeroconf(
|
|||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
|
||||
|
@ -625,7 +626,7 @@ async def test_bridge_zeroconf_already_exists(
|
|||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert entry.data["host"] == "192.168.1.217"
|
||||
|
||||
|
@ -650,7 +651,7 @@ async def test_bridge_zeroconf_ipv6(hass: HomeAssistant) -> None:
|
|||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "invalid_host"
|
||||
|
||||
|
||||
|
@ -676,7 +677,7 @@ async def test_bridge_connection_failed(
|
|||
# a warning message should have been logged that the bridge could not be reached
|
||||
assert "Error while attempting to retrieve discovery information" in caplog.text
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
# test again with zeroconf discovered wrong bridge IP
|
||||
|
@ -697,7 +698,7 @@ async def test_bridge_connection_failed(
|
|||
},
|
||||
),
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
# test again with homekit discovered wrong bridge IP
|
||||
|
@ -714,7 +715,7 @@ async def test_bridge_connection_failed(
|
|||
type="mock_type",
|
||||
),
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
# repeat test with import flow
|
||||
|
@ -723,5 +724,5 @@ async def test_bridge_connection_failed(
|
|||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={"host": "blah"},
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue