Skip to content

Commit e156661

Browse files
feat: add ohsomedb feature flag to api request models
1 parent 13561c8 commit e156661

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

ohsome_quality_api/api/request_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class IndicatorRequest(BaseBpolys, BaseRequestContext):
7777
alias="topic",
7878
)
7979
include_figure: bool = True
80+
ohsomedb: bool = False
8081

8182
@field_validator("topic")
8283
@classmethod

ohsome_quality_api/oqt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from geojson import Feature, FeatureCollection
77

88
from ohsome_quality_api.indicators.base import BaseIndicator as Indicator
9+
from ohsome_quality_api.indicators.currentness.indicator import Currentness
910
from ohsome_quality_api.topics.models import BaseTopic as Topic
1011
from ohsome_quality_api.topics.models import TopicData, TopicDefinition
1112
from ohsome_quality_api.utils.helper import get_class_from_key
@@ -58,6 +59,7 @@ async def _create_indicator(
5859
feature: Feature,
5960
topic: Topic,
6061
include_figure: bool = True,
62+
ohsomedb: bool = False,
6163
**kwargs,
6264
) -> Indicator:
6365
"""Create an indicator from scratch."""
@@ -74,7 +76,10 @@ async def _create_indicator(
7476
)
7577

7678
logging.info("Run preprocessing")
77-
await indicator.preprocess()
79+
if isinstance(indicator, Currentness):
80+
await indicator.preprocess(ohsomedb=ohsomedb)
81+
else:
82+
await indicator.preprocess()
7883

7984
logging.info("Run calculation")
8085
indicator.calculate()

tests/integrationtests/api/test_indicators.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ def test_indicators(
122122
assert schema.is_valid(response.json())
123123

124124

125+
@oqapi_vcr.use_cassette
126+
def test_indicators_currentness(
127+
client,
128+
bpolys,
129+
headers,
130+
schema,
131+
):
132+
"""Minimal viable request for a single bpoly."""
133+
endpoint = ENDPOINT + "currentness"
134+
parameters = {"bpolys": bpolys, "topic": "building-count", "ohsomedb": True}
135+
response = client.post(endpoint, json=parameters, headers=headers)
136+
assert schema.is_valid(response.json())
137+
138+
125139
@oqapi_vcr.use_cassette
126140
def test_indicators_attribute_completeness(
127141
client,

tests/integrationtests/test_geodatabase.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ async def _test_get_connection():
1919
assert result[0] == 1
2020

2121

22+
@pytest.mark.asyncio
23+
async def test_get_connection_ohsomedb():
24+
async with db_client.get_connection() as conn:
25+
result = await conn.fetchrow("SELECT 1")
26+
assert result[0] == 1
27+
28+
2229
def test_get_shdi_single_intersection_feature(feature):
2330
"""Input geometry intersects only with one SHDI region."""
2431
result = asyncio.run(db_client.get_shdi(feature))

tests/unittests/api/test_request_models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def test_indicator_request_include_figure(bpolys, topic_key_minimal):
9595
IndicatorRequest(bpolys=bpolys, topic=topic_key_minimal, include_figure=False)
9696

9797

98+
@pytest.mark.usefixtures("mock_request_context_minimal")
99+
def test_indicator_request_ohsomedb(bpolys, topic_key_minimal):
100+
IndicatorRequest(bpolys=bpolys, topic=topic_key_minimal, ohsomedb=False)
101+
IndicatorRequest(bpolys=bpolys, topic=topic_key_minimal, ohsomedb=True)
102+
103+
98104
def test_indicator_request_invalid_topic(bpolys):
99105
with pytest.raises(ValidationError):
100106
IndicatorRequest(bpolys=bpolys, topic="foo")

0 commit comments

Comments
 (0)