Abort nexia import if the username is already configured (#34863)
This commit is contained in:
1 parent
3bf1cf4f85
commit
5f7711e7a6
5 files changed
+47
-3
No files matched your search
@@ -74,3 +74,44 @@ async def test_form_cannot_connect(hass):
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_import(hass):
|
||||
"""Test we get the form with import source."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.nexia.config_flow.NexiaHome.get_name",
|
||||
return_value="myhouse",
|
||||
), patch(
|
||||
"homeassistant.components.nexia.config_flow.NexiaHome.login",
|
||||
side_effect=MagicMock(),
|
||||
), patch(
|
||||
"homeassistant.components.nexia.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.nexia.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "myhouse"
|
||||
assert result["data"] == {
|
||||
CONF_USERNAME: "username",
|
||||
CONF_PASSWORD: "password",
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
||||
)
|
||||
|
||||
assert result2["type"] == "abort"
|
||||
assert result2["reason"] == "already_configured"
|
||||
Reference in new issue
Block a user