From 4cebedbdd846633ae8d210574d60a8ad44645a5e Mon Sep 17 00:00:00 2001 From: jakeross Date: Thu, 13 Nov 2025 17:57:26 -0700 Subject: [PATCH 1/2] fix: implemented well-notes tests --- tests/features/steps/well-notes.py | 81 ++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 16 deletions(-) diff --git a/tests/features/steps/well-notes.py b/tests/features/steps/well-notes.py index a68114252..bb8943b8b 100644 --- a/tests/features/steps/well-notes.py +++ b/tests/features/steps/well-notes.py @@ -16,41 +16,90 @@ from behave import when, then -@when("the user retrieves the well 1") +@when("the user retrieves the well 9999") def step_impl(context): - context.response = context.client.get("thing/water-well/1") + context.response = context.client.get("thing/water-well/9999") + context.notes = {} -@when("the user retrieves the well 9999") +@then("the response should include an error message indicating the well was not found") def step_impl(context): - context.response = context.client.get("thing/water-well/9999") + assert {"detail": "Thing with ID 9999 not found."} == context.response.json() -@then("the response should contain a current_location field") +@then("the notes should be a non-empty string") def step_impl(context): - assert "current_location" in context.response.json() + for k, note in context.notes.items(): + assert note, f"{k} Note is empty" -@then("the response should include notes") +@when("the user retrieves the well by ID via path parameter") def step_impl(context): - assert "notes" in context.response.json() - context.notes = context.response.json()["notes"] + context.response = context.client.get( + f"thing/water-well/{context.objects['wells'][0].id}" + ) + context.notes = {} -@then("the response should include an error message indicating the well was not found") +@then( + "null values in the response should be represented as JSON null (not placeholder strings)" +) def step_impl(context): - assert {"detail": "Thing with ID 9999 not found."} == context.response.json() + data = context.response.json() + for k, v in data.items(): + if v == "": + assert v is None, f"Value for key {k} is an empty string but should be null" -@then("the response should include well_construction_notes") +@then( + "the response should include location notes (i.e. driving directions and geographic well location notes)" +) def step_impl(context): - assert "well_construction_notes" in context.response.json() - context.notes = context.response.json()["well_construction_notes"] + data = context.response.json() + location = data["current_location"] + assert "notes" in location, "Response does not include location notes" + assert location["notes"] is not None, "Location notes is null" + context.notes["location"] = location["notes"] -@then("the notes should be a non-empty string") +@then( + "the response should include construction notes (i.e. pump notes and other construction notes)" +) +def step_impl(context): + data = context.response.json() + assert ( + "well_construction_notes" in data + ), "Response does not include construction notes" + assert data["well_construction_notes"] is not None, "Construction notes is null" + context.notes["construction"] = data["well_construction_notes"] + + +@then("the response should include general well notes (catch all notes field)") +def step_impl(context): + data = context.response.json() + assert "notes" in data, "Response does not include notes" + assert data["notes"] is not None, "Notes is null" + context.notes["general"] = data["notes"] + + +@then( + "the response should include measuring notes (notes about measuring/visiting the well, on Access form)" +) +def step_impl(context): + data = context.response.json() + assert "measuring_notes" in data, "Response does not include measuring notes" + assert data["measuring_notes"] is not None, "Measuring notes is null" + context.notes["measuring"] = data["measuring_notes"] + + +@then( + "the response should include water notes (i.e. water bearing zone information and other info from ose reports)" +) def step_impl(context): - assert bool(context.notes) == True + data = context.response.json() + assert "water_notes" in data, "Response does not include water notes" + assert data["water_notes"] is not None, "Water notes is null" + context.notes["water"] = data["water_notes"] # ============= EOF ============================================= From ed7960ac1809290394ee1398a50efe992d40e616 Mon Sep 17 00:00:00 2001 From: jakeross Date: Thu, 13 Nov 2025 19:02:51 -0700 Subject: [PATCH 2/2] fix: add notes fields to well and thing models --- db/thing.py | 3 +++ schemas/thing.py | 4 ++++ tests/features/environment.py | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/db/thing.py b/db/thing.py index 3465fd54b..57874a639 100644 --- a/db/thing.py +++ b/db/thing.py @@ -52,6 +52,9 @@ class Thing(Base, AutoBaseMixin, ReleaseMixin, StatusHistoryMixin, PermissionMix nullable=True, comment="To audit where the data came from in NM_Aquifer if it was transferred over", ) + notes = mapped_column(Text, nullable=True) + measuring_notes = mapped_column(Text, nullable=True) + water_notes = mapped_column(Text, nullable=True) # TODO: should `name` be unique? name: Mapped[str] = mapped_column( diff --git a/schemas/thing.py b/schemas/thing.py index cd741c758..3d1c291df 100644 --- a/schemas/thing.py +++ b/schemas/thing.py @@ -154,6 +154,10 @@ class WellResponse(BaseThingResponse): well_casing_materials: list[CasingMaterial] = [] well_construction_notes: str | None = None + water_notes: str | None = None + measuring_notes: str | None = None + notes: str | None = None + @field_validator("well_purposes", mode="before") def populate_well_purposes_with_strings(cls, well_purposes): if well_purposes is not None: diff --git a/tests/features/environment.py b/tests/features/environment.py index aad9b0dc2..bda642768 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -29,7 +29,6 @@ Deployment, TransducerObservationBlock, ) - from db.engine import session_ctx @@ -78,6 +77,9 @@ def add_well(context, session, location, name_num): well_construction_notes="Test well construction notes", well_casing_diameter=5.0, well_casing_depth=10.0, + notes="These are some test well notes", + measuring_notes="These are some measuring notes", + water_notes="This are some water notes", ) session.add(well) session.commit() @@ -203,6 +205,7 @@ def add_transducer_observation(context, session, block, deployment_id, value): def before_all(context): context.objects = {} rebuild = False + # rebuild = True with session_ctx() as session: if rebuild: erase_and_rebuild_db(session)