Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions tests/features/steps/api_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -67,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:
Expand Down Expand Up @@ -95,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:
Expand Down
49 changes: 49 additions & 0 deletions tests/features/steps/thing-query.py
Original file line number Diff line number Diff line change
@@ -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"
Comment thread
jirhiker marked this conversation as resolved.


# ============= EOF =============================================
Loading