Remove retired query paths and repository compatibility branches, and share task test fixtures. Cancel pending questions and resolve their notifications when recovering expired runs.
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
import asyncio
|
|
from datetime import datetime, timezone
|
|
from unittest.mock import AsyncMock
|
|
|
|
from app.api.v1.endpoints import scada as scada_endpoint
|
|
from app.services import timeseries_history as history
|
|
from app.domain.schemas.timeseries_history import ElementHistoryQuery
|
|
|
|
|
|
PROJECT_SCADA = {
|
|
"device_id": "fengyang-pressure-1",
|
|
"device_type": "pressure",
|
|
"node_id": "J1",
|
|
"link_id": None,
|
|
"api_query_id": "query-1",
|
|
"measurement_unit": "m",
|
|
"transmission_mode": "realtime",
|
|
"transmission_frequency": None,
|
|
"reliability": 1.0,
|
|
"x": 117.1,
|
|
"y": 32.9,
|
|
"longitude": 121.5,
|
|
"latitude": 30.9,
|
|
}
|
|
START_TIME = datetime(2026, 6, 1, tzinfo=timezone.utc)
|
|
END_TIME = datetime(2026, 6, 2, tzinfo=timezone.utc)
|
|
|
|
|
|
def test_history_uses_current_project_metadata(monkeypatch):
|
|
postgres = object()
|
|
mappings = AsyncMock(return_value=[PROJECT_SCADA.copy()])
|
|
monkeypatch.setattr(history.ScadaInfoRepository, "get_scadas_for_elements", mappings)
|
|
monkeypatch.setattr(history.ScadaRepository, "get_scada_by_ids_time_range", AsyncMock(return_value=[{
|
|
"time": START_TIME, "device_id": PROJECT_SCADA["device_id"],
|
|
"monitored_value": 26.5, "cleaned_value": 26.0,
|
|
}]))
|
|
result = asyncio.run(history.TimeseriesHistoryService.query(object(), postgres, ElementHistoryQuery(
|
|
start_time=START_TIME, end_time=END_TIME,
|
|
elements=[{"element_id": "J1", "element_type": "junction", "device_ids": [PROJECT_SCADA["device_id"]]}],
|
|
)))
|
|
assert mappings.await_args.args == (postgres, ["J1"], [])
|
|
assert len(result.series) == 2
|
|
assert all(item.device_id == PROJECT_SCADA["device_id"] and item.element_id == "J1" for item in result.series)
|
|
assert [item.points[0].value for item in result.series] == [26.5, 26.0]
|
|
|
|
|
|
def test_scada_info_endpoint_uses_current_project_connection(monkeypatch):
|
|
monkeypatch.setattr(
|
|
scada_endpoint.ScadaInfoRepository,
|
|
"get_scadas",
|
|
AsyncMock(return_value=[PROJECT_SCADA.copy()]),
|
|
)
|
|
|
|
result = asyncio.run(scada_endpoint.get_scada_devices(object()))
|
|
|
|
assert result == [PROJECT_SCADA]
|