Add config flow for Tile (#36173)
* Overhaul Tile * Adjust coverage * Fix tests * Code review * Code review * Remove unused config flow step * Revert "Remove unused config flow step" This reverts commit cb206e044672deb7f681d2a3ae0be03762854fc0. * Fix tests
This commit is contained in:
1 parent
fae80621fb
commit
7a3c2e1f6c
13 files changed
+462
-110
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Define tests for the Tile component."""
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Define tests for the Tile config flow."""
|
||||
from pytile.errors import TileError
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.tile import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_duplicate_error(hass):
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
conf = {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
|
||||
MockConfigEntry(domain=DOMAIN, unique_id="user@host.com", data=conf).add_to_hass(
|
||||
hass
|
||||
)
|
||||
|
||||
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_invalid_credentials(hass):
|
||||
"""Test that invalid credentials key throws an error."""
|
||||
conf = {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tile.config_flow.async_login", side_effect=TileError,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] == {"base": "invalid_credentials"}
|
||||
|
||||
|
||||
async def test_step_import(hass):
|
||||
"""Test that the import step works."""
|
||||
conf = {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tile.async_setup_entry", return_value=True
|
||||
), patch("homeassistant.components.tile.config_flow.async_login"):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
|
||||
)
|
||||
print(result)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "user@host.com"
|
||||
assert result["data"] == {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
|
||||
|
||||
async def test_step_user(hass):
|
||||
"""Test that the user step works."""
|
||||
conf = {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tile.async_setup_entry", return_value=True
|
||||
), patch("homeassistant.components.tile.config_flow.async_login"):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
)
|
||||
print(result)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "user@host.com"
|
||||
assert result["data"] == {
|
||||
CONF_USERNAME: "user@host.com",
|
||||
CONF_PASSWORD: "123abc",
|
||||
}
|
||||
Reference in new issue
Block a user