core/tests/components/uptime/test_config_flow.py

49 lines
1.4 KiB
Python
Raw Normal View History

2022-03-12 11:36:08 +00:00
"""Tests for the Uptime config flow."""
import pytest
from syrupy.assertion import SnapshotAssertion
2022-03-12 11:36:08 +00:00
from homeassistant.components.uptime.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER
2022-03-12 11:36:08 +00:00
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
2022-03-12 11:36:08 +00:00
from tests.common import MockConfigEntry
@pytest.mark.usefixtures("mock_setup_entry")
2022-03-12 11:36:08 +00:00
async def test_full_user_flow(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
2022-03-12 11:36:08 +00:00
) -> None:
"""Test the full user configuration flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result.get("type") == FlowResultType.FORM
assert result.get("step_id") == "user"
2022-03-12 11:36:08 +00:00
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={},
)
assert result2.get("type") == FlowResultType.CREATE_ENTRY
assert result2 == snapshot
2022-03-12 11:36:08 +00:00
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(
DOMAIN, context={"source": SOURCE_USER}
2022-03-12 11:36:08 +00:00
)
assert result.get("type") == FlowResultType.ABORT
2022-03-12 11:36:08 +00:00
assert result.get("reason") == "single_instance_allowed"