Improve code quality in sql integration (#71705)

This commit is contained in:
G Johansson 2022-05-13 01:40:00 +02:00 committed by GitHub
parent ae89a1243a
commit a746d7c1d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 34 deletions

View file

@ -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