2022-03-07 17:58:29 +00:00
|
|
|
"""Tests for the Season config flow."""
|
2024-03-08 13:47:22 +00:00
|
|
|
|
2022-03-07 17:58:29 +00:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
2023-03-05 16:07:32 +00:00
|
|
|
from homeassistant.components.season.const import DOMAIN, TYPE_ASTRONOMICAL
|
|
|
|
from homeassistant.config_entries import SOURCE_USER
|
|
|
|
from homeassistant.const import CONF_TYPE
|
2022-03-07 17:58:29 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-07-07 19:28:18 +00:00
|
|
|
from homeassistant.data_entry_flow import FlowResultType
|
2022-03-07 17:58:29 +00:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_full_user_flow(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
mock_setup_entry: MagicMock,
|
|
|
|
) -> None:
|
|
|
|
"""Test the full user configuration flow."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result.get("type") == FlowResultType.FORM
|
2023-04-11 08:00:17 +00:00
|
|
|
assert result.get("step_id") == "user"
|
2022-03-07 17:58:29 +00:00
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
user_input={CONF_TYPE: TYPE_ASTRONOMICAL},
|
|
|
|
)
|
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result2.get("type") == FlowResultType.CREATE_ENTRY
|
2022-03-07 17:58:29 +00:00
|
|
|
assert result2.get("title") == "Season"
|
|
|
|
assert result2.get("data") == {CONF_TYPE: TYPE_ASTRONOMICAL}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_single_instance_allowed(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
) -> None:
|
|
|
|
"""Test we abort if already setup."""
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
2023-03-05 16:07:32 +00:00
|
|
|
DOMAIN, context={"source": SOURCE_USER}, data={CONF_TYPE: TYPE_ASTRONOMICAL}
|
2022-03-07 17:58:29 +00:00
|
|
|
)
|
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result.get("type") == FlowResultType.ABORT
|
2022-03-07 17:58:29 +00:00
|
|
|
assert result.get("reason") == "already_configured"
|