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:
@@ -97,6 +97,31 @@ def test_update_validates_nodes_before_write(monkeypatch):
|
||||
)
|
||||
|
||||
|
||||
def test_list_sensor_placements_batches_node_lookup(monkeypatch):
|
||||
first = _run()
|
||||
second = {**_run(), "run_id": uuid4(), "sensor_locations": ["J2", "J3"]}
|
||||
lookup_calls = []
|
||||
monkeypatch.setattr(
|
||||
sensor_placement.sensor_placement_repository,
|
||||
"get_all_sensor_placements",
|
||||
lambda _network: [first, second],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
sensor_placement.sensor_placement_repository,
|
||||
"get_sensor_placement_nodes",
|
||||
lambda _network, node_ids: lookup_calls.append(node_ids)
|
||||
or [
|
||||
{**_point(), "node_id": node_id}
|
||||
for node_id in node_ids
|
||||
],
|
||||
)
|
||||
|
||||
runs = sensor_placement.list_sensor_placement_runs("tjwater_v2")
|
||||
|
||||
assert lookup_calls == [["J1", "J2", "J3"]]
|
||||
assert [len(run["sensor_points"]) for run in runs] == [2, 2]
|
||||
|
||||
|
||||
def test_sensor_nodes_query_uses_new_network_and_gis_schemas(monkeypatch):
|
||||
cursor = _mock_project_cursor(monkeypatch)
|
||||
cursor.fetchall.return_value = []
|
||||
@@ -108,6 +133,9 @@ def test_sensor_nodes_query_uses_new_network_and_gis_schemas(monkeypatch):
|
||||
assert "network.links" in query
|
||||
assert "gis.node_geometries" in query
|
||||
assert "ST_Transform(g.geom, 3857)" in query
|
||||
assert "l.start_node_id = ANY(%s)" in query
|
||||
assert "l.end_node_id = ANY(%s)" in query
|
||||
assert "CROSS JOIN LATERAL" not in query
|
||||
assert cursor.execute.call_args.args[1] == (["J1"], ["J1"], ["J1"])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user