Search/replace RESULT_TYPE_* by FlowResultType enum (#74656)
This commit is contained in:
parent
46beae9061
commit
a6244eea28
142 changed files with 1463 additions and 1849 deletions
|
@ -14,11 +14,7 @@ from homeassistant.components.ssdp import ATTR_UPNP_FRIENDLY_NAME, ATTR_UPNP_UDN
|
|||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_SSDP, SOURCE_USER
|
||||
from homeassistant.const import CONF_DEVICES, CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .const import CONF_FAKE_NAME, MOCK_CONFIG
|
||||
|
||||
|
@ -70,13 +66,13 @@ async def test_user(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], user_input=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "10.0.0.1"
|
||||
assert result["data"][CONF_HOST] == "10.0.0.1"
|
||||
assert result["data"][CONF_PASSWORD] == "fake_pass"
|
||||
|
@ -91,7 +87,7 @@ async def test_user_auth_failed(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"]["base"] == "invalid_auth"
|
||||
|
||||
|
@ -103,7 +99,7 @@ async def test_user_not_successful(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
|
@ -112,13 +108,13 @@ async def test_user_already_configured(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert not result["result"].unique_id
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
|
@ -132,7 +128,7 @@ async def test_reauth_success(hass: HomeAssistant, fritz: Mock):
|
|||
context={"source": SOURCE_REAUTH, "entry_id": mock_config.entry_id},
|
||||
data=mock_config.data,
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
|
@ -143,7 +139,7 @@ async def test_reauth_success(hass: HomeAssistant, fritz: Mock):
|
|||
},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "reauth_successful"
|
||||
assert mock_config.data[CONF_USERNAME] == "other_fake_user"
|
||||
assert mock_config.data[CONF_PASSWORD] == "other_fake_password"
|
||||
|
@ -161,7 +157,7 @@ async def test_reauth_auth_failed(hass: HomeAssistant, fritz: Mock):
|
|||
context={"source": SOURCE_REAUTH, "entry_id": mock_config.entry_id},
|
||||
data=mock_config.data,
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
|
@ -172,7 +168,7 @@ async def test_reauth_auth_failed(hass: HomeAssistant, fritz: Mock):
|
|||
},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
assert result["errors"]["base"] == "invalid_auth"
|
||||
|
||||
|
@ -189,7 +185,7 @@ async def test_reauth_not_successful(hass: HomeAssistant, fritz: Mock):
|
|||
context={"source": SOURCE_REAUTH, "entry_id": mock_config.entry_id},
|
||||
data=mock_config.data,
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
|
@ -200,16 +196,16 @@ async def test_reauth_not_successful(hass: HomeAssistant, fritz: Mock):
|
|||
},
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"test_data,expected_result",
|
||||
[
|
||||
(MOCK_SSDP_DATA["ip4_valid"], RESULT_TYPE_FORM),
|
||||
(MOCK_SSDP_DATA["ip6_valid"], RESULT_TYPE_FORM),
|
||||
(MOCK_SSDP_DATA["ip6_invalid"], RESULT_TYPE_ABORT),
|
||||
(MOCK_SSDP_DATA["ip4_valid"], FlowResultType.FORM),
|
||||
(MOCK_SSDP_DATA["ip6_valid"], FlowResultType.FORM),
|
||||
(MOCK_SSDP_DATA["ip6_invalid"], FlowResultType.ABORT),
|
||||
],
|
||||
)
|
||||
async def test_ssdp(
|
||||
|
@ -224,7 +220,7 @@ async def test_ssdp(
|
|||
)
|
||||
assert result["type"] == expected_result
|
||||
|
||||
if expected_result == RESULT_TYPE_ABORT:
|
||||
if expected_result == FlowResultType.ABORT:
|
||||
return
|
||||
|
||||
assert result["step_id"] == "confirm"
|
||||
|
@ -233,7 +229,7 @@ async def test_ssdp(
|
|||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "fake_pass", CONF_USERNAME: "fake_user"},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == CONF_FAKE_NAME
|
||||
assert result["data"][CONF_HOST] == urlparse(test_data.ssdp_location).hostname
|
||||
assert result["data"][CONF_PASSWORD] == "fake_pass"
|
||||
|
@ -249,14 +245,14 @@ async def test_ssdp_no_friendly_name(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_NO_NAME
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "fake_pass", CONF_USERNAME: "fake_user"},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "10.0.0.1"
|
||||
assert result["data"][CONF_HOST] == "10.0.0.1"
|
||||
assert result["data"][CONF_PASSWORD] == "fake_pass"
|
||||
|
@ -271,7 +267,7 @@ async def test_ssdp_auth_failed(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
assert result["errors"] == {}
|
||||
|
||||
|
@ -279,7 +275,7 @@ async def test_ssdp_auth_failed(hass: HomeAssistant, fritz: Mock):
|
|||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "whatever", CONF_USERNAME: "whatever"},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
assert result["errors"]["base"] == "invalid_auth"
|
||||
|
||||
|
@ -291,14 +287,14 @@ async def test_ssdp_not_successful(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "whatever", CONF_USERNAME: "whatever"},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
|
@ -309,14 +305,14 @@ async def test_ssdp_not_supported(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_PASSWORD: "whatever", CONF_USERNAME: "whatever"},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "not_supported"
|
||||
|
||||
|
||||
|
@ -325,13 +321,13 @@ async def test_ssdp_already_in_progress_unique_id(hass: HomeAssistant, fritz: Mo
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_in_progress"
|
||||
|
||||
|
||||
|
@ -340,7 +336,7 @@ async def test_ssdp_already_in_progress_host(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "confirm"
|
||||
|
||||
MOCK_NO_UNIQUE_ID = dataclasses.replace(MOCK_SSDP_DATA["ip4_valid"])
|
||||
|
@ -349,7 +345,7 @@ async def test_ssdp_already_in_progress_host(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_NO_UNIQUE_ID
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_in_progress"
|
||||
|
||||
|
||||
|
@ -358,12 +354,12 @@ async def test_ssdp_already_configured(hass: HomeAssistant, fritz: Mock):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=MOCK_USER_DATA
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert not result["result"].unique_id
|
||||
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_SSDP}, data=MOCK_SSDP_DATA["ip4_valid"]
|
||||
)
|
||||
assert result2["type"] == RESULT_TYPE_ABORT
|
||||
assert result2["type"] == FlowResultType.ABORT
|
||||
assert result2["reason"] == "already_configured"
|
||||
assert result["result"].unique_id == "only-a-test"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue