forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_schema_config_entry_flow.py
72 lines (55 loc) · 2.5 KB
/
test_schema_config_entry_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Tests for the schema based data entry flows."""
from __future__ import annotations
from unittest.mock import patch
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers.schema_config_entry_flow import (
SchemaConfigFlowHandler,
SchemaFlowFormStep,
SchemaFlowMenuStep,
)
from tests.common import mock_platform
TEST_DOMAIN = "test"
async def test_menu_step(hass: HomeAssistant) -> None:
"""Test menu step."""
MENU_1 = ["option1", "option2"]
MENU_2 = ["option3", "option4"]
CONFIG_FLOW: dict[str, SchemaFlowFormStep | SchemaFlowMenuStep] = {
"user": SchemaFlowMenuStep(MENU_1),
"option1": SchemaFlowFormStep(vol.Schema({}), next_step=lambda _: "menu2"),
"menu2": SchemaFlowMenuStep(MENU_2),
"option3": SchemaFlowFormStep(vol.Schema({}), next_step="option4"),
"option4": SchemaFlowFormStep(vol.Schema({})),
}
class TestConfigFlow(SchemaConfigFlowHandler, domain=TEST_DOMAIN):
"""Handle a config or options flow for Derivative."""
config_flow = CONFIG_FLOW
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")
with patch.dict(config_entries.HANDLERS, {TEST_DOMAIN: TestConfigFlow}):
result = await hass.config_entries.flow.async_init(
TEST_DOMAIN, context={"source": "user"}
)
assert result["type"] == FlowResultType.MENU
assert result["step_id"] == "user"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"next_step_id": "option1"},
)
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "option1"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == FlowResultType.MENU
assert result["step_id"] == "menu2"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"next_step_id": "option3"},
)
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "option3"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "option4"
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == FlowResultType.CREATE_ENTRY