From 7f316b6aff20173ff1d980f6299b7e84c8575038 Mon Sep 17 00:00:00 2001 From: zack-rma Date: Fri, 21 Aug 2026 13:48:02 -0700 Subject: [PATCH] Initial integration tests for gate changes --- tests/cda/locations/gate-changes_test.py | 144 +++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/cda/locations/gate-changes_test.py diff --git a/tests/cda/locations/gate-changes_test.py b/tests/cda/locations/gate-changes_test.py new file mode 100644 index 0000000..d95d981 --- /dev/null +++ b/tests/cda/locations/gate-changes_test.py @@ -0,0 +1,144 @@ +import pytest + +import cwms +import cwms.locations.gate_changes as gc +import cwms.locations.physical_locations as pl + +TEST_OFFICE = "SPK" +TEST_PROJECT_ID = "BIGH" +TEST_LOCATION_ID = "BIGH-CG100" +START = "2024-01-01T00:00:00Z" +END = "2024-01-02T00:00:00Z" + +TEST_PROJECT_LOCATION = { + "name": TEST_PROJECT_ID, + "latitude": 40.0, + "longitude": -105.0, + "elevation": 1000.0, + "horizontal-datum": "NAD83", + "vertical-datum": "NAVD88", + "office-id": TEST_OFFICE, + "location-type": "TESTING", + "location-kind": "PROJECT", + "public-name": "Test Location", + "long-name": "A pytest-generated location", + "timezone-name": "America/Chicago", + "nation": "US", +} + +TEST_LOCATION = { + "name": TEST_LOCATION_ID, + "latitude": 40.0, + "longitude": -105.0, + "elevation": 1000.0, + "horizontal-datum": "NAD83", + "vertical-datum": "NAVD88", + "office-id": TEST_OFFICE, + "location-type": "TESTING", + "location-kind": "SITE", + "public-name": "Test Location", + "long-name": "A pytest-generated location", + "timezone-name": "America/Chicago", + "nation": "US", +} + +GATE_CHANGE = { + "type": "gate-change", + "project-id": {"office-id": TEST_OFFICE, "name": TEST_PROJECT_ID}, + "change-date": 1704096000000, + "pool-elevation": 3.0, + "protected": true, + "discharge-computation-type": { + "office-id": TEST_OFFICE, + "display-value": "A", + "tooltip": "Adjusted by an automated method", + "active": true, + }, + "reason-type": { + "office-id": TEST_OFFICE, + "display-value": "O", + "tooltip": "Other release", + "active": true, + }, + "notes": "Test notes", + "new-total-discharge-override": 1.0, + "old-total-discharge-override": 2.0, + "discharge-units": "cfs", + "tailwater-elevation": 4.0, + "elevation-units": "ft", + "settings": [ + { + "type": "gate-setting", + "location-id": {"office-id": TEST_OFFICE, "name": TEST_LOCATION_ID}, + "opening": 10.0, + "opening-parameter": "Opening", + "opening-units": "ft", + "invert-elevation": 20.0, + } + ], +} + + +def _cleanup(): + pl.delete_location(TEST_PROJECT_LOCATION) + pl.delete_location(TEST_LOCATION) + + +@pytest.fixture(scope="module", autouse=True) +def setup_data(): + _cleanup() + + pl.store_location(TEST_PROJECT_LOCATION, False) + pl.store_location(TEST_LOCATION, False) + + +@pytest.fixture(autouse=True) +def init_session(): + print("Initializing CWMS API session for gate change tests...") + + +def test_create_get_gate_change(): + gc.store_gate_change(GATE_CHANGE, False) + data = gc.get_all_gate_changes( + TEST_OFFICE, TEST_PROJECT_ID, "", "", True, True, "SI", 10 + ) + found = False + for item in data: + if data == item: + found = True + assert found + + +def test_catalog_gate_changes(): + GATE_CHANGE2 = GATE_CHANGE + new_loc = TEST_LOCATION_ID + "_new" + GATE_CHANGE2["project-id"]["name"] = new_loc + gc.store_gate_change(GATE_CHANGE2, False) + data = gc.get_all_gate_changes(TEST_OFFICE, new_loc, "", "", True, True, "SI", 10) + found = False + assert len(data) >= 1 + for item in data: + if data == item: + found = True + assert found + + +def test_delete_gate_change(): + GATE_CHANGE2 = GATE_CHANGE + new_loc = TEST_LOCATION_ID + "_new2" + GATE_CHANGE2["project-id"]["name"] = new_loc + gc.store_gate_change(GATE_CHANGE2, False) + data = gc.get_all_gate_changes( + TEST_OFFICE, new_loc, START, END, True, True, "SI", 10 + ) + found = False + assert len(data) >= 1 + for item in data: + if data == item: + found = True + assert found + gc.delete_gate_change(TEST_OFFICE, TEST_PROJECT_ID, START, END) + data = gc.get_all_gate_changes( + TEST_OFFICE, new_loc, START, END, True, True, "SI", 10 + ) + assert len(data) == 0