mirror of
https://github.com/home-assistant/core.git
synced 2026-10-07 14:58:11 -04:00
Split user flow init and data submission in synology_dsm config flow tests (#184102)
This commit is contained in:
@@ -4,7 +4,7 @@ HOST = "nas.meontheinternet.com"
|
||||
SERIAL = "mySerial"
|
||||
HOST_2 = "nas.worldwide.me"
|
||||
SERIAL_2 = "mySerial2"
|
||||
PORT = 1234
|
||||
PORT = "1234"
|
||||
USE_SSL = True
|
||||
VERIFY_SSL = False
|
||||
USERNAME = "Home_Assistant"
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
'00-11-32-XX-XX-5A',
|
||||
]),
|
||||
'password': 'password',
|
||||
'port': 1234,
|
||||
'port': '1234',
|
||||
'ssl': True,
|
||||
'username': 'Home_Assistant',
|
||||
'verify_ssl': False,
|
||||
@@ -78,7 +78,7 @@
|
||||
'00-11-32-XX-XX-5A',
|
||||
]),
|
||||
'password': 'password',
|
||||
'port': 1234,
|
||||
'port': '1234',
|
||||
'ssl': True,
|
||||
'username': 'Home_Assistant',
|
||||
'verify_ssl': False,
|
||||
@@ -92,7 +92,7 @@
|
||||
'00-11-32-XX-XX-5A',
|
||||
]),
|
||||
'password': 'password',
|
||||
'port': 1234,
|
||||
'port': '1234',
|
||||
'ssl': True,
|
||||
'username': 'Home_Assistant',
|
||||
'verify_ssl': False,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
'host': 'nas.meontheinternet.com',
|
||||
'mac': '00-11-32-XX-XX-59',
|
||||
'password': '**REDACTED**',
|
||||
'port': 1234,
|
||||
'port': '1234',
|
||||
'ssl': True,
|
||||
'username': '**REDACTED**',
|
||||
'verify_ssl': False,
|
||||
|
||||
@@ -202,20 +202,20 @@ async def test_user(
|
||||
) -> None:
|
||||
"""Test user config."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=None
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service,
|
||||
):
|
||||
# test with all provided
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
@@ -230,15 +230,21 @@ async def test_user(
|
||||
assert result["data"] == snapshot
|
||||
|
||||
service.information.serial = SERIAL_2
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service,
|
||||
):
|
||||
# test without port + False SSL
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: VERIFY_SSL,
|
||||
@@ -257,14 +263,24 @@ async def test_user_2sa(
|
||||
hass: HomeAssistant, service_2sa: MagicMock, snapshot: SnapshotAssertion
|
||||
) -> None:
|
||||
"""Test user with 2sa authentication config."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service_2sa,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "2sa"
|
||||
@@ -306,7 +322,7 @@ async def test_user_vdsm(
|
||||
return_value=service_vdsm,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=None
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
@@ -316,10 +332,9 @@ async def test_user_vdsm(
|
||||
return_value=service_vdsm,
|
||||
):
|
||||
# test with all provided
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
@@ -346,7 +361,7 @@ async def test_user_with_filestation(
|
||||
return_value=service_with_filestation,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=None
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
@@ -356,10 +371,9 @@ async def test_user_with_filestation(
|
||||
return_value=service_with_filestation,
|
||||
):
|
||||
# test with all provided
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
@@ -389,14 +403,20 @@ async def test_backup_share_form_reopened(
|
||||
service_with_filestation: MagicMock,
|
||||
) -> None:
|
||||
"""Test the backup location form can be shown again without losing the input."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service_with_filestation,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
@@ -430,14 +450,20 @@ async def test_backup_share_requires_a_path(
|
||||
service_with_filestation: MagicMock,
|
||||
) -> None:
|
||||
"""Test an empty backup path is rejected instead of looping the flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service_with_filestation,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_PORT: PORT,
|
||||
CONF_SSL: USE_SSL,
|
||||
@@ -503,6 +529,13 @@ async def test_reconfig_user(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
unique_id=SERIAL,
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.config_entries.ConfigEntries.async_reload",
|
||||
@@ -513,10 +546,13 @@ async def test_reconfig_user(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
return_value=service,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
@@ -525,14 +561,20 @@ async def test_reconfig_user(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_login_failed(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
"""Test when we have errors during login."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
service.return_value.login = Mock(
|
||||
side_effect=(SynologyDSMLoginInvalidException(USERNAME))
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {CONF_USERNAME: "invalid_auth"}
|
||||
@@ -541,14 +583,20 @@ async def test_login_failed(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_connection_failed(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
"""Test when we have errors during connection."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
service.return_value.login = Mock(
|
||||
side_effect=SynologyDSMRequestException(OSError("arg"))
|
||||
)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
@@ -558,12 +606,18 @@ async def test_connection_failed(hass: HomeAssistant, service: MagicMock) -> Non
|
||||
@pytest.mark.usefixtures("mock_setup_entry")
|
||||
async def test_unknown_failed(hass: HomeAssistant, service: MagicMock) -> None:
|
||||
"""Test when we have an unknown error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
service.return_value.login = Mock(side_effect=SynologyDSMException(None, None))
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
@@ -575,14 +629,24 @@ async def test_missing_data_after_login(
|
||||
hass: HomeAssistant, service_failed: MagicMock
|
||||
) -> None:
|
||||
"""Test when we have errors during connection."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.synology_dsm.config_flow.SynologyDSM",
|
||||
return_value=service_failed,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
data={CONF_HOST: HOST, CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
CONF_HOST: HOST,
|
||||
CONF_USERNAME: USERNAME,
|
||||
CONF_PASSWORD: PASSWORD,
|
||||
},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "missing_data"}
|
||||
|
||||
Reference in New Issue
Block a user