Skip to content

Commit 2a5ba77

Browse files
committed
fix: implement feature tests for water well and spring thing types
1 parent c56360d commit 2a5ba77

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

tests/features/steps/api_fixture.py

Lines changed: 8 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()
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)