Reorganize WNDB by responsibility and remove legacy scheme endpoints.\n\nRoute analysis and time-series access through project pools, preserve transactional realtime replacement, and refresh GIS materialized views after writes.\n\nAdd database architecture documentation, live pooling coverage, API contract updates, and executable container verification.\n\nBREAKING CHANGE: legacy scheme APIs and flat app.native.wndb module imports are removed.
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from unittest.mock import MagicMock
|
|
|
|
from app.services import scheme_management
|
|
|
|
|
|
def _mock_connection(monkeypatch):
|
|
cursor = MagicMock()
|
|
cursor.rowcount = 1
|
|
connection = MagicMock()
|
|
connection.cursor.return_value.__enter__.return_value = cursor
|
|
context = MagicMock()
|
|
context.__enter__.return_value = connection
|
|
monkeypatch.setattr(scheme_management, "project_connection", lambda _name: context)
|
|
return cursor
|
|
|
|
|
|
def test_repeated_analysis_names_create_distinct_run_ids(monkeypatch) -> None:
|
|
cursor = _mock_connection(monkeypatch)
|
|
arguments = {
|
|
"name": "tjwater_next",
|
|
"scheme_name": "same-window",
|
|
"scheme_type": "burst_analysis",
|
|
"username": "alice",
|
|
"scheme_start_time": "2026-08-24T00:00:00Z",
|
|
"scheme_detail": {},
|
|
}
|
|
|
|
first = scheme_management.create_analysis_run(**arguments)
|
|
second = scheme_management.create_analysis_run(**arguments)
|
|
|
|
assert first != second
|
|
assert cursor.execute.call_count == 2
|
|
assert all(
|
|
"insert into analysis.runs" in call.args[0]
|
|
for call in cursor.execute.call_args_list
|
|
)
|
|
|
|
|
|
def test_update_analysis_run_targets_execution_id(monkeypatch) -> None:
|
|
cursor = _mock_connection(monkeypatch)
|
|
run_id = scheme_management.create_analysis_run(
|
|
name="tjwater_next",
|
|
scheme_name="run",
|
|
scheme_type="burst_analysis",
|
|
username="alice",
|
|
scheme_start_time="2026-08-24T00:00:00Z",
|
|
scheme_detail={},
|
|
)
|
|
cursor.reset_mock()
|
|
|
|
scheme_management.update_analysis_run(
|
|
"tjwater_next",
|
|
run_id,
|
|
status="completed",
|
|
username="alice",
|
|
scheme_detail={"window": "24h"},
|
|
)
|
|
|
|
statement, params = cursor.execute.call_args.args
|
|
assert "where run_id = %s" in statement
|
|
assert params[-1] == run_id
|
|
assert params[1] == "completed"
|