2021-12-28 21:17:53 +01:00
|
|
|
"""Tests for the CPU Speed config flow."""
|
|
|
|
|
2021-12-29 18:54:47 +01:00
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
2021-12-28 21:17:53 +01:00
|
|
|
|
|
|
|
from homeassistant.components.cpuspeed.const import DOMAIN
|
2022-02-24 11:25:42 +01:00
|
|
|
from homeassistant.config_entries import SOURCE_USER
|
2021-12-28 21:17:53 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-07-07 21:28:18 +02:00
|
|
|
from homeassistant.data_entry_flow import FlowResultType
|
2021-12-28 21:17:53 +01:00
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_full_user_flow(
|
|
|
|
hass: HomeAssistant,
|
2021-12-29 18:54:47 +01:00
|
|
|
mock_cpuinfo_config_flow: MagicMock,
|
2021-12-28 21:17:53 +01:00
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
) -> None:
|
|
|
|
"""Test the full user configuration flow."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
|
2024-04-02 23:22:05 +02:00
|
|
|
assert result.get("type") is FlowResultType.FORM
|
2023-04-11 10:00:17 +02:00
|
|
|
assert result.get("step_id") == "user"
|
2021-12-28 21:17:53 +01:00
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
user_input={},
|
|
|
|
)
|
|
|
|
|
2024-04-02 23:22:05 +02:00
|
|
|
assert result2.get("type") is FlowResultType.CREATE_ENTRY
|
2021-12-28 21:17:53 +01:00
|
|
|
assert result2.get("title") == "CPU Speed"
|
|
|
|
assert result2.get("data") == {}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
2021-12-29 18:54:47 +01:00
|
|
|
assert len(mock_cpuinfo_config_flow.mock_calls) == 1
|
2021-12-28 21:17:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def test_already_configured(
|
|
|
|
hass: HomeAssistant,
|
2021-12-29 18:54:47 +01:00
|
|
|
mock_cpuinfo_config_flow: MagicMock,
|
2021-12-28 21:17:53 +01:00
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
) -> None:
|
|
|
|
"""Test we abort if already configured."""
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
|
2024-04-02 23:22:05 +02:00
|
|
|
assert result.get("type") is FlowResultType.ABORT
|
2021-12-28 21:17:53 +01:00
|
|
|
assert result.get("reason") == "already_configured"
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 0
|
2021-12-29 18:54:47 +01:00
|
|
|
assert len(mock_cpuinfo_config_flow.mock_calls) == 0
|
2021-12-28 21:17:53 +01:00
|
|
|
|
|
|
|
|
2021-12-29 18:54:47 +01:00
|
|
|
async def test_not_compatible(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
mock_cpuinfo_config_flow: MagicMock,
|
|
|
|
mock_setup_entry: AsyncMock,
|
|
|
|
) -> None:
|
|
|
|
"""Test we abort the configuration flow when incompatible."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
|
2024-04-02 23:22:05 +02:00
|
|
|
assert result.get("type") is FlowResultType.FORM
|
2023-04-11 10:00:17 +02:00
|
|
|
assert result.get("step_id") == "user"
|
2021-12-29 18:54:47 +01:00
|
|
|
|
|
|
|
mock_cpuinfo_config_flow.return_value = {}
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
user_input={},
|
|
|
|
)
|
|
|
|
|
2024-04-02 23:22:05 +02:00
|
|
|
assert result2.get("type") is FlowResultType.ABORT
|
2021-12-29 18:54:47 +01:00
|
|
|
assert result2.get("reason") == "not_compatible"
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 0
|
|
|
|
assert len(mock_cpuinfo_config_flow.mock_calls) == 1
|