From 2a5ba77d0cb7c49bafce8a9d75bcf69256cabf1b Mon Sep 17 00:00:00 2001 From: jakeross Date: Mon, 3 Nov 2025 15:49:10 -0700 Subject: [PATCH 1/2] fix: implement feature tests for water well and spring thing types --- tests/features/steps/api_fixture.py | 13 +++++--- tests/features/steps/thing-query.py | 49 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 tests/features/steps/thing-query.py diff --git a/tests/features/steps/api_fixture.py b/tests/features/steps/api_fixture.py index 041f6ed59..3a0046dec 100644 --- a/tests/features/steps/api_fixture.py +++ b/tests/features/steps/api_fixture.py @@ -26,23 +26,26 @@ amp_viewer_function, viewer_function, ) -from core.initializers import register_routes, init_lexicon, init_parameter +from core.initializers import ( + register_routes, + init_lexicon, + init_parameter, + erase_and_rebuild_db, +) from db import ( Location, Thing, LocationThingAssociation, - Base, Sensor, LexiconTerm, Group, GroupThingAssociation, ) -from db.engine import session_ctx, engine +from db.engine import session_ctx with session_ctx() as session: if session.query(LexiconTerm).count() == 0: - Base.metadata.drop_all(engine) - Base.metadata.create_all(engine) + erase_and_rebuild_db(session) init_lexicon() init_parameter() diff --git a/tests/features/steps/thing-query.py b/tests/features/steps/thing-query.py new file mode 100644 index 000000000..47a61d896 --- /dev/null +++ b/tests/features/steps/thing-query.py @@ -0,0 +1,49 @@ +# =============================================================================== +# Copyright 2025 ross +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# =============================================================================== + +from behave import when, then + + +@when('the user requests things with type "water well"') +def step_impl(context): + context.response = context.client.get("/thing", params={"thing_type": "water well"}) + + +@then("the response should include at least one thing") +def step_impl(context): + data = context.response.json() + context.data = data["items"] + assert len(context.data) > 0 + + +@then('the response should only include things of type "water well"') +def step_impl(context): + for d in context.data: + assert d["thing_type"] == "water well" + + +@when('the user requests things with type "spring"') +def step_impl(context): + context.response = context.client.get("/thing", params={"thing_type": "spring"}) + + +@then('the response should only include things of type "spring"') +def step_impl(context): + for d in context.data: + assert d["thing_type"] == "spring" + + +# ============= EOF ============================================= From 160aafbd4a2a04a355674752839fe249c28db529 Mon Sep 17 00:00:00 2001 From: jakeross Date: Mon, 3 Nov 2025 17:38:41 -0700 Subject: [PATCH 2/2] fix: add function to create and associate spring with location in api_fixture.py --- tests/features/steps/api_fixture.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/features/steps/api_fixture.py b/tests/features/steps/api_fixture.py index 3a0046dec..c5f875531 100644 --- a/tests/features/steps/api_fixture.py +++ b/tests/features/steps/api_fixture.py @@ -70,6 +70,27 @@ def add_location(lid): return loc +def add_spring(location, sid): + spring = well = Thing( + name=f"SP-{sid:04d}", + first_visit_date="2023-03-03", + thing_type="spring", + release_status="draft", + # well_depth=10, + # hole_depth=10, + # well_construction_notes="Test well construction notes", + # well_casing_diameter=5.0, + # well_casing_depth=10.0, + ) + session.add(spring) + session.commit() + + assoc = LocationThingAssociation(location=location, thing=well) + assoc.effective_start = "2025-02-01T00:00:00Z" + session.add(assoc) + session.commit() + + def add_well(location, wid): well = session.get(Thing, wid) if not well: @@ -98,10 +119,12 @@ def add_well(location, wid): loc = add_location(1) loc2 = add_location(2) loc3 = add_location(3) + loc4 = add_location(4) water_well = add_well(loc, 1) water_well2 = add_well(loc2, 2) water_well3 = add_well(loc3, 3) + spring = add_spring(loc4, 4) sensor = session.get(Sensor, 1) if not sensor: