Modernize SimpliSafe config flow (#32130)
* Modernize SimpliSafe config flow * Fix tests
This commit is contained in:
1 parent
db40b2fc32
commit
f7e336eaa6
4 files changed
+43
-18
No files matched your search
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, PropertyMock, mock_open, patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.simplisafe import DOMAIN, config_flow
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
@@ -20,12 +21,27 @@ async def test_duplicate_error(hass):
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
conf = {CONF_USERNAME: "user@email.com", CONF_PASSWORD: "password"}
|
||||
|
||||
MockConfigEntry(domain=DOMAIN, data=conf).add_to_hass(hass)
|
||||
flow = config_flow.SimpliSafeFlowHandler()
|
||||
flow.hass = hass
|
||||
MockConfigEntry(domain=DOMAIN, unique_id="user@email.com", data=conf).add_to_hass(
|
||||
hass
|
||||
)
|
||||
|
||||
result = await flow.async_step_user(user_input=conf)
|
||||
assert result["errors"] == {CONF_USERNAME: "identifier_exists"}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_get_configured_instances(hass):
|
||||
"""Test retrieving all configured instances."""
|
||||
conf = {CONF_USERNAME: "user@email.com", CONF_PASSWORD: "password"}
|
||||
|
||||
MockConfigEntry(domain=DOMAIN, unique_id="user@email.com", data=conf).add_to_hass(
|
||||
hass
|
||||
)
|
||||
|
||||
assert len(config_flow.configured_instances(hass)) == 1
|
||||
|
||||
|
||||
async def test_invalid_credentials(hass):
|
||||
@@ -36,6 +52,7 @@ async def test_invalid_credentials(hass):
|
||||
|
||||
flow = config_flow.SimpliSafeFlowHandler()
|
||||
flow.hass = hass
|
||||
flow.context = {"source": SOURCE_USER}
|
||||
|
||||
with patch(
|
||||
"simplipy.API.login_via_credentials",
|
||||
@@ -49,6 +66,7 @@ async def test_show_form(hass):
|
||||
"""Test that the form is served with no input."""
|
||||
flow = config_flow.SimpliSafeFlowHandler()
|
||||
flow.hass = hass
|
||||
flow.context = {"source": SOURCE_USER}
|
||||
|
||||
result = await flow.async_step_user(user_input=None)
|
||||
|
||||
@@ -62,6 +80,7 @@ async def test_step_import(hass):
|
||||
|
||||
flow = config_flow.SimpliSafeFlowHandler()
|
||||
flow.hass = hass
|
||||
flow.context = {"source": SOURCE_USER}
|
||||
|
||||
mop = mock_open(read_data=json.dumps({"refresh_token": "12345"}))
|
||||
|
||||
@@ -91,6 +110,7 @@ async def test_step_user(hass):
|
||||
|
||||
flow = config_flow.SimpliSafeFlowHandler()
|
||||
flow.hass = hass
|
||||
flow.context = {"source": SOURCE_USER}
|
||||
|
||||
mop = mock_open(read_data=json.dumps({"refresh_token": "12345"}))
|
||||
|
||||
|
||||
Reference in new issue
Block a user