mirror of
https://github.com/home-assistant/core.git
synced 2026-11-01 03:00:55 -04:00
Refactor SQL's data conversion (#155598)
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
"""Test the sql utils."""
|
||||
|
||||
from datetime import UTC, date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.recorder import Recorder, get_instance
|
||||
from homeassistant.components.sql.util import resolve_db_url, validate_sql_select
|
||||
from homeassistant.components.sql.util import (
|
||||
convert_value,
|
||||
resolve_db_url,
|
||||
validate_sql_select,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
@@ -64,3 +71,23 @@ async def test_invalid_sql_queries(
|
||||
"""Test that various invalid or disallowed SQL queries raise the correct exception."""
|
||||
with pytest.raises(vol.Invalid, match=expected_error_message):
|
||||
validate_sql_select(sql_query)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input", "expected_output"),
|
||||
[
|
||||
(Decimal("199.99"), 199.99),
|
||||
(date(2023, 1, 15), "2023-01-15"),
|
||||
(datetime(2023, 1, 15, 12, 30, 45, tzinfo=UTC), "2023-01-15T12:30:45+00:00"),
|
||||
(b"\xde\xad\xbe\xef", "0xdeadbeef"),
|
||||
("deadbeef", "deadbeef"),
|
||||
(199.99, 199.99),
|
||||
(69, 69),
|
||||
],
|
||||
)
|
||||
async def test_value_conversion(
|
||||
input: Decimal | date | datetime | bytes | str | float,
|
||||
expected_output: str | float,
|
||||
) -> None:
|
||||
"""Test value conversion."""
|
||||
assert convert_value(input) == expected_output
|
||||
|
||||
Reference in New Issue
Block a user