hass-core/tests/components/dynalite/test_config_flow.py
Ziv 4467409e5c
Dynalite Integration (#27841)
* Initial commit

* ran hassfest and gen_requirements_all scripts

* fixes per request from Paulus Schoutsen

* ran gen_requirements_all

* updated library version - removed some debug leftover

* get_requirements again...

* added documentation URL

* ran isort

* changed storage in hass.data[DOMAIN] to use entry_id instead of host

* adopted unit tests to latest fix

* Update const.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-02-10 13:16:04 -08:00

36 lines
1.4 KiB
Python
Executable file

"""Test Dynalite config flow."""
from unittest.mock import Mock, call, patch
from homeassistant.components.dynalite import config_flow
from tests.common import mock_coro
async def test_step_import():
"""Test a successful setup."""
flow_handler = config_flow.DynaliteFlowHandler()
with patch.object(flow_handler, "context", create=True):
with patch.object(flow_handler, "hass", create=True) as mock_hass:
with patch.object(
flow_handler, "async_create_entry", create=True
) as mock_create:
host = "1.2.3.4"
entry1 = Mock()
entry1.data = {"host": host}
entry2 = Mock()
entry2.data = {"host": "5.5"}
mock_hass.config_entries.async_entries = Mock(
return_value=[entry1, entry2]
)
mock_hass.config_entries.async_remove = Mock(
return_value=mock_coro(Mock())
)
await flow_handler.async_step_import({"host": "1.2.3.4"})
mock_hass.config_entries.async_remove.assert_called_once()
assert mock_hass.config_entries.async_remove.mock_calls[0] == call(
entry1.entry_id
)
mock_create.assert_called_once()
assert mock_create.mock_calls[0] == call(
title=host, data={"host": host}
)