mirror of
https://github.com/home-assistant/core.git
synced 2025-08-16 02:51:40 +02:00
Consolidate config entry test cleanup into a single function
This commit is contained in:
@@ -61,6 +61,27 @@ MOCK_DISCOVERY = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def cleanup_entry(
|
||||||
|
hass: HomeAssistant, entry: str | data_entry_flow.FlowResult
|
||||||
|
) -> None:
|
||||||
|
"""Clean up a config entry to ensure all resources acquired are released.
|
||||||
|
|
||||||
|
This works in conjunction with the post-conditions in domain_data_mock and
|
||||||
|
dmr_device_mock to find any resource leaks.
|
||||||
|
"""
|
||||||
|
# Wait for platform to finish setup
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Remove the config entry and device to clean up all resources
|
||||||
|
if isinstance(entry, dict):
|
||||||
|
entry_id: str = entry["result"].entry_id
|
||||||
|
else:
|
||||||
|
entry_id = entry
|
||||||
|
assert await hass.config_entries.async_remove(entry_id) == {
|
||||||
|
"require_restart": False
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow(hass: HomeAssistant) -> None:
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test user-init'd config flow with user entering a valid URL."""
|
"""Test user-init'd config flow with user entering a valid URL."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@@ -83,14 +104,7 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
await cleanup_entry(hass, result)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_uncontactable(
|
async def test_user_flow_uncontactable(
|
||||||
@@ -151,14 +165,7 @@ async def test_user_flow_embedded_st(
|
|||||||
}
|
}
|
||||||
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
assert result["options"] == {CONF_POLL_AVAILABILITY: True}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
await cleanup_entry(hass, result)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_wrong_st(hass: HomeAssistant, domain_data_mock: Mock) -> None:
|
async def test_user_flow_wrong_st(hass: HomeAssistant, domain_data_mock: Mock) -> None:
|
||||||
@@ -240,13 +247,7 @@ async def test_import_flow_ssdp_discovered(
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
await cleanup_entry(hass, entry_id)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_direct_connect(
|
async def test_import_flow_direct_connect(
|
||||||
@@ -286,10 +287,7 @@ async def test_import_flow_direct_connect(
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
await cleanup_entry(hass, entry_id)
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_offline(
|
async def test_import_flow_offline(
|
||||||
@@ -361,14 +359,7 @@ async def test_import_flow_offline(
|
|||||||
CONF_POLL_AVAILABILITY: True,
|
CONF_POLL_AVAILABILITY: True,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
await cleanup_entry(hass, result)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_options(
|
async def test_import_flow_options(
|
||||||
@@ -403,14 +394,7 @@ async def test_import_flow_options(
|
|||||||
CONF_POLL_AVAILABILITY: True,
|
CONF_POLL_AVAILABILITY: True,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wait for platform to be fully setup
|
await cleanup_entry(hass, result)
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_flow_success(hass: HomeAssistant) -> None:
|
async def test_ssdp_flow_success(hass: HomeAssistant) -> None:
|
||||||
@@ -437,11 +421,7 @@ async def test_ssdp_flow_success(hass: HomeAssistant) -> None:
|
|||||||
}
|
}
|
||||||
assert result["options"] == {}
|
assert result["options"] == {}
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
await cleanup_entry(hass, result)
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_flow_unavailable(
|
async def test_ssdp_flow_unavailable(
|
||||||
@@ -476,11 +456,7 @@ async def test_ssdp_flow_unavailable(
|
|||||||
}
|
}
|
||||||
assert result["options"] == {}
|
assert result["options"] == {}
|
||||||
|
|
||||||
# Remove the device to clean up all resources, completing its life cycle
|
await cleanup_entry(hass, result)
|
||||||
entry_id = result["result"].entry_id
|
|
||||||
assert await hass.config_entries.async_remove(entry_id) == {
|
|
||||||
"require_restart": False
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_flow_existing(
|
async def test_ssdp_flow_existing(
|
||||||
|
Reference in New Issue
Block a user