From 8d0be60b90592c36735b5824137738bfe4b6d5dc Mon Sep 17 00:00:00 2001 From: jross Date: Mon, 30 Mar 2026 14:41:09 -0600 Subject: [PATCH 1/2] feat: add location properties to water well response and enhance test coverage --- schemas/location.py | 6 ++++++ schemas/thing.py | 8 ++++++++ services/thing_helper.py | 4 ++++ tests/conftest.py | 3 +++ tests/test_thing.py | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/schemas/location.py b/schemas/location.py index 596545287..50fe28dd9 100644 --- a/schemas/location.py +++ b/schemas/location.py @@ -101,6 +101,9 @@ class GeoJSONProperties(BaseModel): elevation_unit: str = "ft" vertical_datum: str = "NAVD88" elevation_method: ElevationMethod | None + county: str | None = None + state: str | None = None + quad_name: str | None = None utm_coordinates: GeoJSONUTMCoordinates = Field( default_factory=GeoJSONUTMCoordinates ) @@ -154,6 +157,9 @@ def populate_fields(cls, data: Any) -> Any: data_dict["properties"]["notes"] = data_dict.get("notes") data_dict["properties"]["elevation"] = convert_m_to_ft(elevation_m) data_dict["properties"]["elevation_method"] = data_dict.get("elevation_method") + data_dict["properties"]["county"] = data_dict.get("county") + data_dict["properties"]["state"] = data_dict.get("state") + data_dict["properties"]["quad_name"] = data_dict.get("quad_name") data_dict["properties"]["nma_location_notes"] = data_dict.get( "nma_location_notes" ) diff --git a/schemas/thing.py b/schemas/thing.py index cd3483fd7..b3f19287d 100644 --- a/schemas/thing.py +++ b/schemas/thing.py @@ -229,6 +229,13 @@ def remove_records_with_end_date(cls, monitoring_frequencies): return active_frequencies +class WellContactSummaryResponse(BaseResponseModel): + name: str | None = None + organization: str | None = None + role: str + contact_type: str + + class WellResponse(BaseThingResponse): """ Response schema for well details. @@ -262,6 +269,7 @@ class WellResponse(BaseThingResponse): aquifers: list[dict] = [] water_notes: list[NoteResponse] = [] construction_notes: list[NoteResponse] = [] + contacts: list[WellContactSummaryResponse] = [] permissions: list[PermissionHistoryResponse] formation_completion_code: FormationCode | None nma_formation_zone: str | None diff --git a/services/thing_helper.py b/services/thing_helper.py index 221cb1214..14db87068 100644 --- a/services/thing_helper.py +++ b/services/thing_helper.py @@ -28,6 +28,7 @@ from db import ( LocationThingAssociation, Thing, + ThingContactAssociation, Location, WellScreen, WellPurpose, @@ -55,6 +56,9 @@ selectinload(Thing.location_associations).selectinload( LocationThingAssociation.location ), + selectinload(Thing.contact_associations).selectinload( + ThingContactAssociation.contact + ), selectinload(Thing.well_purposes), selectinload(Thing.well_casing_materials), selectinload(Thing.links), diff --git a/tests/conftest.py b/tests/conftest.py index 2705e72a6..5818707bd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -133,7 +133,10 @@ def location(): loc = Location( point="POINT(-107.949533 33.809665)", elevation=2464.9, + county="Sierra", release_status="draft", + state="NM", + quad_name="Hillsboro Peak", ) session.add(loc) diff --git a/tests/test_thing.py b/tests/test_thing.py index 10f8e05fd..8ec2d8417 100644 --- a/tests/test_thing.py +++ b/tests/test_thing.py @@ -668,6 +668,42 @@ def test_get_water_well_details_payload_404_not_found(): assert response.json()["detail"] == "Thing with ID 999999 not found." +def test_get_water_well_by_id_includes_location_properties( + water_well_thing, +): + response = client.get(f"/thing/water-well/{water_well_thing.id}") + + assert response.status_code == 200 + data = response.json() + + assert data["current_location"]["properties"]["county"] == "Sierra" + assert data["current_location"]["properties"]["state"] == "NM" + assert data["current_location"]["properties"]["quad_name"] == "Hillsboro Peak" + + +def test_get_water_wells_includes_contact_summary( + water_well_thing, + contact, +): + response = client.get("/thing/water-well") + + assert response.status_code == 200 + data = response.json() + + well = next(item for item in data["items"] if item["id"] == water_well_thing.id) + assert well["contacts"] == [ + { + "id": contact.id, + "created_at": contact.created_at.astimezone(timezone.utc).strftime(DT_FMT), + "release_status": contact.release_status, + "name": contact.name, + "organization": contact.organization, + "contact_type": contact.contact_type, + "role": contact.role, + } + ] + + def test_get_water_well_by_id_404_not_found(water_well_thing): bad_id = 99999 response = client.get(f"/thing/water-well/{bad_id}") From 14e9066267cc2e3575d3c953d3e18727b0316d76 Mon Sep 17 00:00:00 2001 From: jross Date: Mon, 30 Mar 2026 14:53:33 -0600 Subject: [PATCH 2/2] feat: update well response validation and enhance type safety for contact fields --- schemas/thing.py | 6 ++++-- tests/test_thing.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/schemas/thing.py b/schemas/thing.py index b3f19287d..baa4ec6c2 100644 --- a/schemas/thing.py +++ b/schemas/thing.py @@ -28,6 +28,8 @@ WellPumpType, FormationCode, OriginType, + Role, + ContactType, ) from schemas import BaseCreateModel, BaseUpdateModel, BaseResponseModel, PastOrTodayDate from schemas.group import GroupResponse @@ -232,8 +234,8 @@ def remove_records_with_end_date(cls, monitoring_frequencies): class WellContactSummaryResponse(BaseResponseModel): name: str | None = None organization: str | None = None - role: str - contact_type: str + role: Role + contact_type: ContactType class WellResponse(BaseThingResponse): diff --git a/tests/test_thing.py b/tests/test_thing.py index 8ec2d8417..2dde25fb0 100644 --- a/tests/test_thing.py +++ b/tests/test_thing.py @@ -690,7 +690,10 @@ def test_get_water_wells_includes_contact_summary( assert response.status_code == 200 data = response.json() - well = next(item for item in data["items"] if item["id"] == water_well_thing.id) + well = next( + (item for item in data["items"] if item["id"] == water_well_thing.id), None + ) + assert well is not None, f"Well {water_well_thing.id} not found in response" assert well["contacts"] == [ { "id": contact.id,