mirror of https://github.com/home-assistant/core
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""Tests for the Stookalert config flow."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.components.stookalert.const import CONF_PROVINCE, DOMAIN
|
|
from homeassistant.config_entries import SOURCE_USER
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_full_user_flow(hass: HomeAssistant) -> None:
|
|
"""Test the full user configuration flow."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
)
|
|
|
|
assert result.get("type") is FlowResultType.FORM
|
|
assert result.get("step_id") == "user"
|
|
|
|
with patch(
|
|
"homeassistant.components.stookalert.async_setup_entry", return_value=True
|
|
) as mock_setup_entry:
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input={
|
|
CONF_PROVINCE: "Overijssel",
|
|
},
|
|
)
|
|
|
|
assert result2.get("type") is FlowResultType.CREATE_ENTRY
|
|
assert result2.get("title") == "Overijssel"
|
|
assert result2.get("data") == {
|
|
CONF_PROVINCE: "Overijssel",
|
|
}
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
async def test_already_configured(hass: HomeAssistant) -> None:
|
|
"""Test we abort if the Stookalert province is already configured."""
|
|
MockConfigEntry(
|
|
domain=DOMAIN, data={CONF_PROVINCE: "Overijssel"}, unique_id="Overijssel"
|
|
).add_to_hass(hass)
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
)
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input={
|
|
CONF_PROVINCE: "Overijssel",
|
|
},
|
|
)
|
|
|
|
assert result2.get("type") is FlowResultType.ABORT
|
|
assert result2.get("reason") == "already_configured"
|