|
25 | 25 | viewer_function, |
26 | 26 | amp_viewer_function, |
27 | 27 | ) |
28 | | -from db import Thing, WellScreen, ThingIdLink |
| 28 | +from db import Thing, WellScreen, ThingIdLink, MeasuringPointHistory |
| 29 | +from db.engine import session_ctx |
29 | 30 | from main import app |
30 | 31 | from schemas import DT_FMT |
31 | 32 | from schemas.location import LocationResponse |
@@ -190,6 +191,65 @@ def test_add_water_well_with_measuring_point(location, group): |
190 | 191 | cleanup_post_test(Thing, data["id"]) |
191 | 192 |
|
192 | 193 |
|
| 194 | +def test_add_water_well_missing_measuring_point_height_sets_assumed(location, group): |
| 195 | + payload = { |
| 196 | + "location_id": location.id, |
| 197 | + "group_id": group.id, |
| 198 | + "release_status": "draft", |
| 199 | + "name": "Test Well Missing MP Height", |
| 200 | + } |
| 201 | + |
| 202 | + response = client.post("/thing/water-well", json=payload) |
| 203 | + assert response.status_code == 201 |
| 204 | + data = response.json() |
| 205 | + assert data["measuring_point_height"] == 0 |
| 206 | + assert data["measuring_point_height_is_assumed"] is True |
| 207 | + |
| 208 | + with session_ctx() as session: |
| 209 | + mph = ( |
| 210 | + session.query(MeasuringPointHistory) |
| 211 | + .filter( |
| 212 | + MeasuringPointHistory.thing_id == data["id"], |
| 213 | + MeasuringPointHistory.end_date.is_(None), |
| 214 | + ) |
| 215 | + .one() |
| 216 | + ) |
| 217 | + assert float(mph.measuring_point_height) == 0.0 |
| 218 | + assert mph.measuring_point_height_is_assumed is True |
| 219 | + |
| 220 | + cleanup_post_test(Thing, data["id"]) |
| 221 | + |
| 222 | + |
| 223 | +def test_add_water_well_explicit_measuring_point_height_not_assumed(location, group): |
| 224 | + payload = { |
| 225 | + "location_id": location.id, |
| 226 | + "group_id": group.id, |
| 227 | + "release_status": "draft", |
| 228 | + "name": "Test Well Explicit MP Height", |
| 229 | + "measuring_point_height": 2.5, |
| 230 | + } |
| 231 | + |
| 232 | + response = client.post("/thing/water-well", json=payload) |
| 233 | + assert response.status_code == 201 |
| 234 | + data = response.json() |
| 235 | + assert data["measuring_point_height"] == 2.5 |
| 236 | + assert data["measuring_point_height_is_assumed"] is False |
| 237 | + |
| 238 | + with session_ctx() as session: |
| 239 | + mph = ( |
| 240 | + session.query(MeasuringPointHistory) |
| 241 | + .filter( |
| 242 | + MeasuringPointHistory.thing_id == data["id"], |
| 243 | + MeasuringPointHistory.end_date.is_(None), |
| 244 | + ) |
| 245 | + .one() |
| 246 | + ) |
| 247 | + assert float(mph.measuring_point_height) == 2.5 |
| 248 | + assert mph.measuring_point_height_is_assumed is False |
| 249 | + |
| 250 | + cleanup_post_test(Thing, data["id"]) |
| 251 | + |
| 252 | + |
193 | 253 | @pytest.mark.skip("Needs to be updated per changes made from feature files") |
194 | 254 | def test_add_water_well_409_bad_group_id(location): |
195 | 255 | bad_group_id = 9999 |
|
0 commit comments