2018-11-28 21:20:13 +00:00
|
|
|
"""Tests for OwnTracks config flow."""
|
2019-05-14 09:59:11 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
from tests.common import mock_coro
|
|
|
|
|
|
|
|
|
|
|
|
async def test_config_flow_import(hass):
|
|
|
|
"""Test that we automatically create a config flow."""
|
2019-07-31 19:25:30 +00:00
|
|
|
assert not hass.config_entries.async_entries("owntracks")
|
|
|
|
assert await async_setup_component(hass, "owntracks", {"owntracks": {}})
|
2019-05-14 09:59:11 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert hass.config_entries.async_entries("owntracks")
|
2019-05-14 09:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_config_flow_unload(hass):
|
|
|
|
"""Test unloading a config flow."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.config_entries.ConfigEntries" ".async_forward_entry_setup"
|
|
|
|
) as mock_forward:
|
2019-05-14 09:59:11 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2019-07-31 19:25:30 +00:00
|
|
|
"owntracks", context={"source": "import"}, data={}
|
2019-05-14 09:59:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert len(mock_forward.mock_calls) == 1
|
2019-07-31 19:25:30 +00:00
|
|
|
entry = result["result"]
|
2019-05-14 09:59:11 +00:00
|
|
|
|
|
|
|
assert mock_forward.mock_calls[0][1][0] is entry
|
2019-07-31 19:25:30 +00:00
|
|
|
assert mock_forward.mock_calls[0][1][1] == "device_tracker"
|
|
|
|
assert entry.data["webhook_id"] in hass.data["webhook"]
|
2019-05-14 09:59:11 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.config_entries.ConfigEntries" ".async_forward_entry_unload",
|
|
|
|
return_value=mock_coro(),
|
|
|
|
) as mock_unload:
|
2019-05-14 09:59:11 +00:00
|
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
|
|
|
|
|
|
assert len(mock_unload.mock_calls) == 1
|
|
|
|
assert mock_forward.mock_calls[0][1][0] is entry
|
2019-07-31 19:25:30 +00:00
|
|
|
assert mock_forward.mock_calls[0][1][1] == "device_tracker"
|
|
|
|
assert entry.data["webhook_id"] not in hass.data["webhook"]
|
2019-05-14 09:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_with_cloud_sub(hass):
|
|
|
|
"""Test creating a config flow while subscribed."""
|
2019-10-19 01:08:54 +00:00
|
|
|
hass.config.components.add("cloud")
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.cloud.async_active_subscription", return_value=True
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.cloud.async_create_cloudhook",
|
|
|
|
return_value=mock_coro("https://hooks.nabu.casa/ABCD"),
|
|
|
|
):
|
2019-05-14 09:59:11 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2019-07-31 19:25:30 +00:00
|
|
|
"owntracks", context={"source": "user"}, data={}
|
2019-05-14 09:59:11 +00:00
|
|
|
)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entry = result["result"]
|
|
|
|
assert entry.data["cloudhook"]
|
|
|
|
assert (
|
|
|
|
result["description_placeholders"]["webhook_url"]
|
|
|
|
== "https://hooks.nabu.casa/ABCD"
|
|
|
|
)
|