Improve code quality in sql integration (#71705)
This commit is contained in:
parent
ae89a1243a
commit
a746d7c1d7
6 changed files with 46 additions and 34 deletions
|
@ -115,7 +115,30 @@ async def test_query_no_value(
|
|||
state = hass.states.get("sensor.count_tables")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
text = "SELECT 5 as value where 1=2 returned no results"
|
||||
text = "SELECT 5 as value where 1=2 LIMIT 1; returned no results"
|
||||
assert text in caplog.text
|
||||
|
||||
|
||||
async def test_query_mssql_no_result(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the SQL sensor with a query that returns no value."""
|
||||
config = {
|
||||
"db_url": "mssql://",
|
||||
"query": "SELECT 5 as value where 1=2",
|
||||
"column": "value",
|
||||
"name": "count_tables",
|
||||
}
|
||||
with patch("homeassistant.components.sql.sensor.sqlalchemy"), patch(
|
||||
"homeassistant.components.sql.sensor.sqlalchemy.text",
|
||||
return_value="SELECT TOP 1 5 as value where 1=2",
|
||||
):
|
||||
await init_integration(hass, config)
|
||||
|
||||
state = hass.states.get("sensor.count_tables")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
text = "SELECT TOP 1 5 AS VALUE WHERE 1=2 returned no results"
|
||||
assert text in caplog.text
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue