feat(timeseries): unify element history queries
Generic Container CI/CD / test-build-publish (push) Successful in 2m10s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 2m10s

This commit is contained in:
2026-09-14 12:30:41 +08:00
parent 0685f6dd17
commit 682c26fddd
17 changed files with 888 additions and 531 deletions
@@ -0,0 +1,50 @@
from datetime import UTC, datetime, timedelta
from uuid import uuid4
import pytest
from pydantic import ValidationError
from app.domain.schemas.timeseries_history import ElementHistoryQuery
def _query(**overrides):
start = datetime(2026, 1, 1, tzinfo=UTC)
values = {
"start_time": start,
"end_time": start + timedelta(hours=1),
"mode": "observed",
"elements": [{"element_id": " P1 ", "element_type": "pipe"}],
}
values.update(overrides)
return ElementHistoryQuery(**values)
def test_history_query_normalizes_targets_and_device_ids():
query = _query(
elements=[
{
"element_id": " P1 ",
"element_type": "pipe",
"device_ids": [" D1 ", "D1", "D2"],
}
]
)
assert query.elements[0].element_id == "P1"
assert query.elements[0].device_ids == ["D1", "D2"]
def test_analysis_comparison_requires_run_id():
with pytest.raises(ValidationError, match="run_id is required"):
_query(mode="analysis_comparison")
def test_other_modes_reject_run_id():
with pytest.raises(ValidationError, match="only valid"):
_query(run_id=uuid4())
def test_history_query_rejects_reversed_time_range():
start = datetime(2026, 1, 1, tzinfo=UTC)
with pytest.raises(ValidationError, match="start_time must be earlier"):
_query(start_time=start, end_time=start)