Skip to content

Commit 21c205d

Browse files
committed
add tests for updating a config entry
1 parent dd555d6 commit 21c205d

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

tests/test_config_flow.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ async def test_import_flow(hass, pyscript_bypass_setup):
7575
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
7676

7777

78-
async def test_import_flow_update_entry(hass):
79-
"""Test import config flow updates existing entry."""
78+
async def test_import_flow_update_allow_all_imports(hass):
79+
"""Test import config flow updates existing entry when `allow_all_imports` has changed."""
8080
result = await hass.config_entries.flow.async_init(
8181
DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})
8282
)
@@ -91,6 +91,36 @@ async def test_import_flow_update_entry(hass):
9191
assert result["reason"] == "updated_entry"
9292

9393

94+
async def test_import_flow_update_apps_from_none(hass):
95+
"""Test import config flow updates existing entry when `apps` has changed from None to something."""
96+
result = await hass.config_entries.flow.async_init(
97+
DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({})
98+
)
99+
100+
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
101+
102+
result = await hass.config_entries.flow.async_init(
103+
DOMAIN, context={"source": SOURCE_IMPORT}, data={"apps": {"test_app": {"param": 1}}}
104+
)
105+
106+
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
107+
assert result["reason"] == "updated_entry"
108+
109+
110+
async def test_import_flow_update_apps_to_none(hass):
111+
"""Test import config flow updates existing entry when `apps` has changed from something to None."""
112+
result = await hass.config_entries.flow.async_init(
113+
DOMAIN, context={"source": SOURCE_IMPORT}, data=PYSCRIPT_SCHEMA({"apps": {"test_app": {"param": 1}}})
114+
)
115+
116+
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
117+
118+
result = await hass.config_entries.flow.async_init(DOMAIN, context={"source": SOURCE_IMPORT}, data={})
119+
120+
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
121+
assert result["reason"] == "updated_entry"
122+
123+
94124
async def test_import_flow_no_update(hass):
95125
"""Test import config flow doesn't update existing entry when data is same."""
96126
result = await hass.config_entries.flow.async_init(

0 commit comments

Comments
 (0)