Skip to content

Commit 5d1a800

Browse files
authored
Merge pull request #224 from DataIntegrationGroup/BDMS-219-Implement-feature-test-for-BDMS-218
BDMS-218: implement feature tests for water well and spring thing types
2 parents ddb4c24 + 160aafb commit 5d1a800

2 files changed

Lines changed: 80 additions & 5 deletions

File tree

tests/features/steps/api_fixture.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@
2626
amp_viewer_function,
2727
viewer_function,
2828
)
29-
from core.initializers import register_routes, init_lexicon, init_parameter
29+
from core.initializers import (
30+
register_routes,
31+
init_lexicon,
32+
init_parameter,
33+
erase_and_rebuild_db,
34+
)
3035
from db import (
3136
Location,
3237
Thing,
3338
LocationThingAssociation,
34-
Base,
3539
Sensor,
3640
LexiconTerm,
3741
Group,
3842
GroupThingAssociation,
3943
)
40-
from db.engine import session_ctx, engine
44+
from db.engine import session_ctx
4145

4246
with session_ctx() as session:
4347
if session.query(LexiconTerm).count() == 0:
44-
Base.metadata.drop_all(engine)
45-
Base.metadata.create_all(engine)
48+
erase_and_rebuild_db(session)
4649

4750
init_lexicon()
4851
init_parameter()
@@ -67,6 +70,27 @@ def add_location(lid):
6770
return loc
6871

6972

73+
def add_spring(location, sid):
74+
spring = well = Thing(
75+
name=f"SP-{sid:04d}",
76+
first_visit_date="2023-03-03",
77+
thing_type="spring",
78+
release_status="draft",
79+
# well_depth=10,
80+
# hole_depth=10,
81+
# well_construction_notes="Test well construction notes",
82+
# well_casing_diameter=5.0,
83+
# well_casing_depth=10.0,
84+
)
85+
session.add(spring)
86+
session.commit()
87+
88+
assoc = LocationThingAssociation(location=location, thing=well)
89+
assoc.effective_start = "2025-02-01T00:00:00Z"
90+
session.add(assoc)
91+
session.commit()
92+
93+
7094
def add_well(location, wid):
7195
well = session.get(Thing, wid)
7296
if not well:
@@ -95,10 +119,12 @@ def add_well(location, wid):
95119
loc = add_location(1)
96120
loc2 = add_location(2)
97121
loc3 = add_location(3)
122+
loc4 = add_location(4)
98123

99124
water_well = add_well(loc, 1)
100125
water_well2 = add_well(loc2, 2)
101126
water_well3 = add_well(loc3, 3)
127+
spring = add_spring(loc4, 4)
102128

103129
sensor = session.get(Sensor, 1)
104130
if not sensor:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# ===============================================================================
2+
# Copyright 2025 ross
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ===============================================================================
16+
17+
from behave import when, then
18+
19+
20+
@when('the user requests things with type "water well"')
21+
def step_impl(context):
22+
context.response = context.client.get("/thing", params={"thing_type": "water well"})
23+
24+
25+
@then("the response should include at least one thing")
26+
def step_impl(context):
27+
data = context.response.json()
28+
context.data = data["items"]
29+
assert len(context.data) > 0
30+
31+
32+
@then('the response should only include things of type "water well"')
33+
def step_impl(context):
34+
for d in context.data:
35+
assert d["thing_type"] == "water well"
36+
37+
38+
@when('the user requests things with type "spring"')
39+
def step_impl(context):
40+
context.response = context.client.get("/thing", params={"thing_type": "spring"})
41+
42+
43+
@then('the response should only include things of type "spring"')
44+
def step_impl(context):
45+
for d in context.data:
46+
assert d["thing_type"] == "spring"
47+
48+
49+
# ============= EOF =============================================

0 commit comments

Comments
 (0)