1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Use FlowResultType enum in config flow tests A-M (#114681)

This commit is contained in:
Joost Lekkerkerker
2024-04-03 09:21:17 +02:00
committed by GitHub
parent a767530970
commit b9281327c4
111 changed files with 997 additions and 961 deletions

View File

@@ -11,6 +11,7 @@ from homeassistant import config_entries
from homeassistant.components import dhcp
from homeassistant.components.broadlink.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from . import get_device
@@ -42,7 +43,7 @@ async def test_flow_user_works(hass: HomeAssistant) -> None:
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {}
@@ -52,7 +53,7 @@ async def test_flow_user_works(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "finish"
assert result["errors"] == {}
@@ -61,7 +62,7 @@ async def test_flow_user_works(hass: HomeAssistant) -> None:
{"name": device.name},
)
assert result["type"] == "create_entry"
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == device.name
assert result["data"] == device.get_entry_data()
@@ -93,7 +94,7 @@ async def test_flow_user_already_in_progress(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_in_progress"
@@ -120,7 +121,7 @@ async def test_flow_user_mac_already_configured(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert dict(mock_entry.data) == device.get_entry_data()
@@ -139,7 +140,7 @@ async def test_flow_user_invalid_ip_address(hass: HomeAssistant) -> None:
{"host": "0.0.0.1"},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "invalid_host"}
@@ -156,7 +157,7 @@ async def test_flow_user_invalid_hostname(hass: HomeAssistant) -> None:
{"host": "pancakemaster.local"},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "invalid_host"}
@@ -175,7 +176,7 @@ async def test_flow_user_device_not_found(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"}
@@ -195,7 +196,7 @@ async def test_flow_user_device_not_supported(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "not_supported"
@@ -211,7 +212,7 @@ async def test_flow_user_network_unreachable(hass: HomeAssistant) -> None:
{"host": "192.168.1.32"},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"}
@@ -228,7 +229,7 @@ async def test_flow_user_os_error(hass: HomeAssistant) -> None:
{"host": "192.168.1.32"},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "unknown"}
@@ -249,7 +250,7 @@ async def test_flow_auth_authentication_error(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reset"
assert result["errors"] == {"base": "invalid_auth"}
@@ -270,7 +271,7 @@ async def test_flow_auth_network_timeout(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "auth"
assert result["errors"] == {"base": "cannot_connect"}
@@ -291,7 +292,7 @@ async def test_flow_auth_firmware_error(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "auth"
assert result["errors"] == {"base": "unknown"}
@@ -312,7 +313,7 @@ async def test_flow_auth_network_unreachable(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "auth"
assert result["errors"] == {"base": "cannot_connect"}
@@ -333,7 +334,7 @@ async def test_flow_auth_os_error(hass: HomeAssistant) -> None:
{"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "auth"
assert result["errors"] == {"base": "unknown"}
@@ -365,7 +366,7 @@ async def test_flow_reset_works(hass: HomeAssistant) -> None:
{"name": device.name},
)
assert result["type"] == "create_entry"
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == device.name
assert result["data"] == device.get_entry_data()
@@ -386,7 +387,7 @@ async def test_flow_unlock_works(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "unlock"
assert result["errors"] == {}
@@ -400,7 +401,7 @@ async def test_flow_unlock_works(hass: HomeAssistant) -> None:
{"name": device.name},
)
assert result["type"] == "create_entry"
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == device.name
assert result["data"] == device.get_entry_data()
@@ -430,7 +431,7 @@ async def test_flow_unlock_network_timeout(hass: HomeAssistant) -> None:
{"unlock": True},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "unlock"
assert result["errors"] == {"base": "cannot_connect"}
@@ -457,7 +458,7 @@ async def test_flow_unlock_firmware_error(hass: HomeAssistant) -> None:
{"unlock": True},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "unlock"
assert result["errors"] == {"base": "unknown"}
@@ -484,7 +485,7 @@ async def test_flow_unlock_network_unreachable(hass: HomeAssistant) -> None:
{"unlock": True},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "unlock"
assert result["errors"] == {"base": "cannot_connect"}
@@ -511,7 +512,7 @@ async def test_flow_unlock_os_error(hass: HomeAssistant) -> None:
{"unlock": True},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "unlock"
assert result["errors"] == {"base": "unknown"}
@@ -542,7 +543,7 @@ async def test_flow_do_not_unlock(hass: HomeAssistant) -> None:
{"name": device.name},
)
assert result["type"] == "create_entry"
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == device.name
assert result["data"] == device.get_entry_data()
@@ -561,7 +562,7 @@ async def test_flow_import_works(hass: HomeAssistant) -> None:
data={"host": device.host},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "finish"
assert result["errors"] == {}
@@ -570,7 +571,7 @@ async def test_flow_import_works(hass: HomeAssistant) -> None:
{"name": device.name},
)
assert result["type"] == "create_entry"
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == device.name
assert result["data"]["host"] == device.host
assert result["data"]["mac"] == device.mac
@@ -595,7 +596,7 @@ async def test_flow_import_already_in_progress(hass: HomeAssistant) -> None:
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=data
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_in_progress"
@@ -613,7 +614,7 @@ async def test_flow_import_host_already_configured(hass: HomeAssistant) -> None:
data={"host": device.host},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
@@ -636,7 +637,7 @@ async def test_flow_import_mac_already_configured(hass: HomeAssistant) -> None:
data={"host": device.host},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert mock_entry.data["host"] == device.host
@@ -654,7 +655,7 @@ async def test_flow_import_device_not_found(hass: HomeAssistant) -> None:
data={"host": "192.168.1.32"},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
@@ -670,7 +671,7 @@ async def test_flow_import_device_not_supported(hass: HomeAssistant) -> None:
data={"host": device.host},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "not_supported"
@@ -683,7 +684,7 @@ async def test_flow_import_invalid_ip_address(hass: HomeAssistant) -> None:
data={"host": "0.0.0.1"},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "invalid_host"
@@ -696,7 +697,7 @@ async def test_flow_import_invalid_hostname(hass: HomeAssistant) -> None:
data={"host": "hotdog.local"},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "invalid_host"
@@ -709,7 +710,7 @@ async def test_flow_import_network_unreachable(hass: HomeAssistant) -> None:
data={"host": "192.168.1.64"},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
@@ -722,7 +723,7 @@ async def test_flow_import_os_error(hass: HomeAssistant) -> None:
data={"host": "192.168.1.64"},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "unknown"
@@ -740,7 +741,7 @@ async def test_flow_reauth_works(hass: HomeAssistant) -> None:
DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reset"
mock_api = device.get_mock_api()
@@ -751,7 +752,7 @@ async def test_flow_reauth_works(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert dict(mock_entry.data) == device.get_entry_data()
@@ -785,7 +786,7 @@ async def test_flow_reauth_invalid_host(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "invalid_host"}
@@ -819,7 +820,7 @@ async def test_flow_reauth_valid_host(hass: HomeAssistant) -> None:
{"host": device.host, "timeout": device.timeout},
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert mock_entry.data["host"] == device.host
@@ -846,7 +847,7 @@ async def test_dhcp_can_finish(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "form"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "finish"
result2 = await hass.config_entries.flow.async_configure(
@@ -855,7 +856,7 @@ async def test_dhcp_can_finish(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == "Living Room"
assert result2["data"] == {
"host": "1.2.3.4",
@@ -880,7 +881,7 @@ async def test_dhcp_fails_to_connect(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
@@ -899,7 +900,7 @@ async def test_dhcp_unreachable(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
@@ -918,7 +919,7 @@ async def test_dhcp_connect_unknown_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "unknown"
@@ -939,7 +940,7 @@ async def test_dhcp_device_not_supported(hass: HomeAssistant) -> None:
),
)
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "not_supported"
@@ -964,7 +965,7 @@ async def test_dhcp_already_exists(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
@@ -989,6 +990,6 @@ async def test_dhcp_updates_host(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert result["type"] == "abort"
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert mock_entry.data["host"] == "4.5.6.7"