Case sensitive SQL queries checks (#62752)

This commit is contained in:
Diogo Gomes 2022-01-07 16:19:30 +00:00 committed by GitHub
parent 04796c4410
commit d5d8eefded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -31,6 +31,30 @@ async def test_query(hass):
assert state.attributes["value"] == 5
async def test_query_limit(hass):
"""Test the SQL sensor with a query containing 'LIMIT' in lowercase."""
config = {
"sensor": {
"platform": "sql",
"db_url": "sqlite://",
"queries": [
{
"name": "count_tables",
"query": "SELECT 5 as value limit 1",
"column": "value",
}
],
}
}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
state = hass.states.get("sensor.count_tables")
assert state.state == "5"
assert state.attributes["value"] == 5
async def test_invalid_query(hass):
"""Test the SQL sensor for invalid queries."""
with pytest.raises(vol.Invalid):