mirror of
https://github.com/home-assistant/core.git
synced 2025-11-24 02:07:01 +00:00
Allow empty db in SQL options flow (#77777)
This commit is contained in:
committed by
Paulus Schoutsen
parent
3240f8f938
commit
2bfcdc66b6
@@ -20,7 +20,7 @@ from . import (
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
async def test_form(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test we get the form."""
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
@@ -52,7 +52,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_flow_success(hass: HomeAssistant) -> None:
|
||||
async def test_import_flow_success(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test a successful import of yaml."""
|
||||
|
||||
with patch(
|
||||
@@ -79,7 +79,7 @@ async def test_import_flow_success(hass: HomeAssistant) -> None:
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_flow_already_exist(hass: HomeAssistant) -> None:
|
||||
async def test_import_flow_already_exist(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test import of yaml already exist."""
|
||||
|
||||
MockConfigEntry(
|
||||
@@ -102,7 +102,7 @@ async def test_import_flow_already_exist(hass: HomeAssistant) -> None:
|
||||
assert result3["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_flow_fails_db_url(hass: HomeAssistant) -> None:
|
||||
async def test_flow_fails_db_url(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test config flow fails incorrect db url."""
|
||||
result4 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
@@ -123,7 +123,7 @@ async def test_flow_fails_db_url(hass: HomeAssistant) -> None:
|
||||
assert result4["errors"] == {"db_url": "db_url_invalid"}
|
||||
|
||||
|
||||
async def test_flow_fails_invalid_query(hass: HomeAssistant) -> None:
|
||||
async def test_flow_fails_invalid_query(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test config flow fails incorrect db url."""
|
||||
result4 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
@@ -169,7 +169,7 @@ async def test_flow_fails_invalid_query(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_options_flow(hass: HomeAssistant) -> None:
|
||||
async def test_options_flow(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test options config flow."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@@ -218,7 +218,9 @@ async def test_options_flow(hass: HomeAssistant) -> None:
|
||||
}
|
||||
|
||||
|
||||
async def test_options_flow_name_previously_removed(hass: HomeAssistant) -> None:
|
||||
async def test_options_flow_name_previously_removed(
|
||||
hass: HomeAssistant, recorder_mock
|
||||
) -> None:
|
||||
"""Test options config flow where the name was missing."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@@ -269,7 +271,7 @@ async def test_options_flow_name_previously_removed(hass: HomeAssistant) -> None
|
||||
}
|
||||
|
||||
|
||||
async def test_options_flow_fails_db_url(hass: HomeAssistant) -> None:
|
||||
async def test_options_flow_fails_db_url(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test options flow fails incorrect db url."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
@@ -312,7 +314,7 @@ async def test_options_flow_fails_db_url(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
async def test_options_flow_fails_invalid_query(
|
||||
hass: HomeAssistant,
|
||||
hass: HomeAssistant, recorder_mock
|
||||
) -> None:
|
||||
"""Test options flow fails incorrect query and template."""
|
||||
entry = MockConfigEntry(
|
||||
@@ -367,3 +369,58 @@ async def test_options_flow_fails_invalid_query(
|
||||
"column": "size",
|
||||
"unit_of_measurement": "MiB",
|
||||
}
|
||||
|
||||
|
||||
async def test_options_flow_db_url_empty(hass: HomeAssistant, recorder_mock) -> None:
|
||||
"""Test options config flow with leaving db_url empty."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={},
|
||||
options={
|
||||
"db_url": "sqlite://",
|
||||
"name": "Get Value",
|
||||
"query": "SELECT 5 as value",
|
||||
"column": "value",
|
||||
"unit_of_measurement": "MiB",
|
||||
"value_template": None,
|
||||
},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.sql.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.sql.async_setup_entry",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.sql.config_flow.sqlalchemy.create_engine",
|
||||
):
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={
|
||||
"query": "SELECT 5 as size",
|
||||
"column": "size",
|
||||
"unit_of_measurement": "MiB",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
"name": "Get Value",
|
||||
"db_url": "sqlite://",
|
||||
"query": "SELECT 5 as size",
|
||||
"column": "size",
|
||||
"value_template": None,
|
||||
"unit_of_measurement": "MiB",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user