refactor(db)!: clean up business SQL access
- make realtime replacement and analysis result writes transactional\n- consolidate SCADA repositories and remove process-global project state\n- validate SCADA batches and use indexed GIS-backed business queries\n\nBREAKING CHANGE: remove the public analysis result writer and the pipeline-health network_name query parameter.
This commit is contained in:
@@ -31,7 +31,7 @@ def test_repeated_analysis_names_create_distinct_run_ids(monkeypatch) -> None:
|
||||
assert first != second
|
||||
assert cursor.execute.call_count == 2
|
||||
assert all(
|
||||
"insert into analysis.runs" in call.args[0]
|
||||
"insert into analysis.runs" in call.args[0].lower()
|
||||
for call in cursor.execute.call_args_list
|
||||
)
|
||||
|
||||
@@ -57,6 +57,43 @@ def test_update_analysis_run_targets_execution_id(monkeypatch) -> None:
|
||||
)
|
||||
|
||||
statement, params = cursor.execute.call_args.args
|
||||
assert "where run_id = %s" in statement
|
||||
assert "where run_id = %s" in statement.lower()
|
||||
assert params[-1] == run_id
|
||||
assert params[1] == "completed"
|
||||
|
||||
|
||||
def test_run_and_business_result_share_one_transaction(monkeypatch) -> None:
|
||||
connection = object()
|
||||
context = MagicMock()
|
||||
context.__enter__.return_value = connection
|
||||
monkeypatch.setattr(
|
||||
scheme_management,
|
||||
"project_transaction",
|
||||
lambda _name: context,
|
||||
)
|
||||
created_ids = []
|
||||
result_ids = []
|
||||
monkeypatch.setattr(
|
||||
scheme_management.AnalysisRepository,
|
||||
"create_run_sync",
|
||||
lambda conn, **kwargs: created_ids.append((conn, kwargs["run_id"])),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
scheme_management.AnalysisRepository,
|
||||
"insert_result_sync",
|
||||
lambda conn, run_id, **_kwargs: result_ids.append((conn, run_id)),
|
||||
)
|
||||
|
||||
run_id = scheme_management.store_analysis_run_with_result(
|
||||
name="tjwater_v2",
|
||||
scheme_name="leak-run",
|
||||
scheme_type="dma_leak_identification",
|
||||
username="alice",
|
||||
scheme_start_time="2026-08-24T00:00:00Z",
|
||||
scheme_detail={},
|
||||
result_type="leakage_identification",
|
||||
result_payload={"rows": []},
|
||||
)
|
||||
|
||||
assert created_ids == [(connection, run_id)]
|
||||
assert result_ids == [(connection, run_id)]
|
||||
|
||||
Reference in New Issue
Block a user