68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
|
"""Test the Open Thread Border Router config flow."""
|
||
|
from unittest.mock import patch
|
||
|
|
||
|
from homeassistant.components import hassio, otbr
|
||
|
from homeassistant.core import HomeAssistant
|
||
|
from homeassistant.data_entry_flow import FlowResultType
|
||
|
|
||
|
from tests.common import MockConfigEntry, MockModule, mock_integration
|
||
|
|
||
|
HASSIO_DATA = hassio.HassioServiceInfo(
|
||
|
config={"host": "blah", "port": "bluh"},
|
||
|
name="blah",
|
||
|
slug="blah",
|
||
|
)
|
||
|
|
||
|
|
||
|
async def test_hassio_discovery_flow(hass: HomeAssistant) -> None:
|
||
|
"""Test the hassio discovery flow."""
|
||
|
with patch(
|
||
|
"homeassistant.components.otbr.async_setup_entry",
|
||
|
return_value=True,
|
||
|
) as mock_setup_entry:
|
||
|
result = await hass.config_entries.flow.async_init(
|
||
|
otbr.DOMAIN, context={"source": "hassio"}, data=HASSIO_DATA
|
||
|
)
|
||
|
|
||
|
expected_data = {
|
||
|
"url": f"http://{HASSIO_DATA.config['host']}:{HASSIO_DATA.config['port']}",
|
||
|
}
|
||
|
|
||
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||
|
assert result["title"] == "Thread"
|
||
|
assert result["data"] == expected_data
|
||
|
assert result["options"] == {}
|
||
|
assert len(mock_setup_entry.mock_calls) == 1
|
||
|
|
||
|
config_entry = hass.config_entries.async_entries(otbr.DOMAIN)[0]
|
||
|
assert config_entry.data == expected_data
|
||
|
assert config_entry.options == {}
|
||
|
assert config_entry.title == "Thread"
|
||
|
assert config_entry.unique_id is None
|
||
|
|
||
|
|
||
|
async def test_config_flow_single_entry(hass: HomeAssistant) -> None:
|
||
|
"""Test only a single entry is allowed."""
|
||
|
mock_integration(hass, MockModule("hassio"))
|
||
|
|
||
|
# Setup the config entry
|
||
|
config_entry = MockConfigEntry(
|
||
|
data={},
|
||
|
domain=otbr.DOMAIN,
|
||
|
options={},
|
||
|
title="Thread",
|
||
|
)
|
||
|
config_entry.add_to_hass(hass)
|
||
|
|
||
|
with patch(
|
||
|
"homeassistant.components.homeassistant_yellow.async_setup_entry",
|
||
|
return_value=True,
|
||
|
) as mock_setup_entry:
|
||
|
result = await hass.config_entries.flow.async_init(
|
||
|
otbr.DOMAIN, context={"source": "hassio"}, data=HASSIO_DATA
|
||
|
)
|
||
|
|
||
|
assert result["type"] == FlowResultType.ABORT
|
||
|
assert result["reason"] == "single_instance_allowed"
|
||
|
mock_setup_entry.assert_not_called()
|