2
2
3
3
from unittest .mock import patch
4
4
5
- from homeassistant import config_entries , data_entry_flow
5
+ from homeassistant . config_entries import SOURCE_USER
6
6
from homeassistant .const import CONF_NAME
7
7
from homeassistant .core import HomeAssistant
8
+ from homeassistant .data_entry_flow import FlowResultType
8
9
import pytest
9
- from pytest_homeassistant_custom_component .common import MockConfigEntry
10
10
11
11
from custom_components .knmi .const import DOMAIN
12
12
@@ -27,18 +27,18 @@ def bypass_setup_fixture():
27
27
yield
28
28
29
29
30
- # Here we simiulate a successful config flow from the backend.
30
+ # Here we simulate a successful config flow from the backend.
31
31
# Note that we use the `mocked_data` fixture here because
32
32
# we want the config flow validation to succeed during the test.
33
33
async def test_successful_config_flow (hass : HomeAssistant , mocked_data ):
34
34
"""Test a successful config flow."""
35
35
# Initialize a config flow
36
36
result = await hass .config_entries .flow .async_init (
37
- DOMAIN , context = {"source" : config_entries . SOURCE_USER }
37
+ DOMAIN , context = {"source" : SOURCE_USER }
38
38
)
39
39
40
40
# Check that the config flow shows the user form as the first step
41
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_FORM
41
+ assert result ["type" ] == FlowResultType . FORM
42
42
assert result ["step_id" ] == "user"
43
43
44
44
# If a user were to fill in all fields, it would result in this function call
@@ -48,7 +48,7 @@ async def test_successful_config_flow(hass: HomeAssistant, mocked_data):
48
48
49
49
# Check that the config flow is complete and a new entry is created with
50
50
# the input data
51
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_CREATE_ENTRY
51
+ assert result ["type" ] == FlowResultType . CREATE_ENTRY
52
52
assert result ["title" ] == MOCK_CONFIG [CONF_NAME ]
53
53
assert result ["data" ] == MOCK_CONFIG
54
54
assert result ["result" ]
@@ -61,17 +61,17 @@ async def test_successful_config_flow(hass: HomeAssistant, mocked_data):
61
61
async def test_failed_config_flow (hass : HomeAssistant , config_flow_exceptions ):
62
62
"""Test a failed config flow due to credential validation failure."""
63
63
result = await hass .config_entries .flow .async_init (
64
- DOMAIN , context = {"source" : config_entries . SOURCE_USER }
64
+ DOMAIN , context = {"source" : SOURCE_USER }
65
65
)
66
66
67
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_FORM
67
+ assert result ["type" ] == FlowResultType . FORM
68
68
assert result ["step_id" ] == "user"
69
69
70
70
result = await hass .config_entries .flow .async_configure (
71
71
result ["flow_id" ], user_input = MOCK_CONFIG
72
72
)
73
73
74
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_FORM
74
+ assert result ["type" ] == FlowResultType . FORM
75
75
assert "base" in result ["errors" ]
76
76
77
77
@@ -86,7 +86,7 @@ async def test_options_flow(hass: HomeAssistant):
86
86
result = await hass .config_entries .options .async_init (config_entry .entry_id )
87
87
88
88
# Verify that the first options step is a user form
89
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_FORM
89
+ assert result ["type" ] == FlowResultType . FORM
90
90
assert result ["step_id" ] == "user"
91
91
92
92
# Enter some fake data into the form
@@ -96,7 +96,7 @@ async def test_options_flow(hass: HomeAssistant):
96
96
)
97
97
98
98
# Verify that the flow finishes
99
- assert result ["type" ] == data_entry_flow . RESULT_TYPE_CREATE_ENTRY
99
+ assert result ["type" ] == FlowResultType . CREATE_ENTRY
100
100
assert result ["title" ] == MOCK_CONFIG [CONF_NAME ]
101
101
102
102
# Verify that the options were updated
0 commit comments