Skip to content

Commit 4e0ff80

Browse files
committed
add tests
1 parent 4265418 commit 4e0ff80

File tree

3 files changed

+100
-14
lines changed

3 files changed

+100
-14
lines changed

tests/routes/test_items.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,62 @@ def test_items_datetime(app):
423423
)
424424
assert response.status_code == 422
425425
assert response.headers["content-type"] == "application/json"
426+
427+
428+
def test_items_geometry_return_options(app):
429+
"""Test /items endpoint with geometry return options."""
430+
response = app.get("/collections/public.landsat_wrs/items?ids=1&geom-column=none")
431+
assert response.status_code == 200
432+
assert response.headers["content-type"] == "application/geo+json"
433+
body = response.json()
434+
assert len(body["features"]) == 1
435+
assert body["numberMatched"] == 1
436+
assert body["numberReturned"] == 1
437+
assert body["features"][0]["id"] == "1"
438+
assert body["features"][0]["properties"]["ogc_fid"] == 1
439+
assert "geometry" not in body["features"][0]
440+
441+
response = app.get("/collections/public.landsat_wrs/items?ids=1&bbox-only=true")
442+
assert response.status_code == 200
443+
assert response.headers["content-type"] == "application/geo+json"
444+
body = response.json()
445+
assert len(body["features"]) == 1
446+
assert body["numberMatched"] == 1
447+
assert body["numberReturned"] == 1
448+
assert body["features"][0]["id"] == "1"
449+
assert body["features"][0]["properties"]["ogc_fid"] == 1
450+
assert body["features"][0]["geometry"] == {
451+
"coordinates": [
452+
[
453+
[-22.2153, 79.6888],
454+
[-22.2153, 81.8555],
455+
[-8.97407, 81.8555],
456+
[-8.97407, 79.6888],
457+
[-22.2153, 79.6888],
458+
]
459+
],
460+
"type": "Polygon",
461+
}
462+
463+
response = app.get("/collections/public.landsat_wrs/items?ids=1&simplify=.001")
464+
assert response.status_code == 200
465+
assert response.headers["content-type"] == "application/geo+json"
466+
body = response.json()
467+
assert len(body["features"]) == 1
468+
assert body["numberMatched"] == 1
469+
assert body["numberReturned"] == 1
470+
assert body["features"][0]["id"] == "1"
471+
assert body["features"][0]["properties"]["ogc_fid"] == 1
472+
print(body["features"][0]["geometry"])
473+
assert body["features"][0]["geometry"] == {
474+
"coordinates": [
475+
[
476+
[-10.803, 80.989],
477+
[-8.974, 80.342],
478+
[-16.985, 79.689],
479+
[-22.215, 81.092],
480+
[-13.255, 81.856],
481+
[-10.803, 80.989],
482+
]
483+
]
484+
}

tifeatures/factory.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ def collection(
401401
),
402402
model.Link(
403403
href=self.url_for(
404-
request, "collection", collectionId=collection.id
404+
request,
405+
"collection",
406+
collectionId=collection.id,
405407
)
406408
+ "?f=html",
407409
rel="alternate",
@@ -530,7 +532,8 @@ async def items(
530532
alias="bbox-only",
531533
),
532534
simplify: Optional[float] = Query(
533-
None, description="Simplify the output geometry."
535+
None,
536+
description="Simplify the output geometry to given threshold in decimal degrees.",
534537
),
535538
):
536539
offset = offset or 0

tifeatures/layer.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ def _where(
198198

199199
w.append(
200200
logic.V(col.name)
201-
== logic.S(pg_funcs.cast(pg_funcs.cast(val, "text"), col.type))
201+
== logic.S(
202+
pg_funcs.cast(pg_funcs.cast(val, "text"), col.type)
203+
)
202204
)
203205

204206
if w:
@@ -224,9 +226,13 @@ def _where(
224226

225227
datetime_column = self.datetime_column(dt)
226228
if not datetime_column:
227-
raise InvalidDatetimeColumnName(f"Invalid Datetime Column: {dt}.")
229+
raise InvalidDatetimeColumnName(
230+
f"Invalid Datetime Column: {dt}."
231+
)
228232

229-
wheres.append(self._datetime_filter_to_sql(datetime, datetime_column.name))
233+
wheres.append(
234+
self._datetime_filter_to_sql(datetime, datetime_column.name)
235+
)
230236

231237
# `CQL` filter
232238
if cql is not None:
@@ -242,28 +248,42 @@ def _datetime_filter_to_sql(self, interval: List[str], dt_name: str):
242248

243249
else:
244250
start = (
245-
parse_rfc3339(interval[0]) if not interval[0] in ["..", ""] else None
251+
parse_rfc3339(interval[0])
252+
if not interval[0] in ["..", ""]
253+
else None
254+
)
255+
end = (
256+
parse_rfc3339(interval[1])
257+
if not interval[1] in ["..", ""]
258+
else None
246259
)
247-
end = parse_rfc3339(interval[1]) if not interval[1] in ["..", ""] else None
248260

249261
if start is None and end is None:
250262
raise InvalidDatetime(
251263
"Double open-ended datetime intervals are not allowed."
252264
)
253265

254266
if start is not None and end is not None and start > end:
255-
raise InvalidDatetime("Start datetime cannot be before end datetime.")
267+
raise InvalidDatetime(
268+
"Start datetime cannot be before end datetime."
269+
)
256270

257271
if not start:
258-
return logic.V(dt_name) <= logic.S(pg_funcs.cast(end, "timestamptz"))
272+
return logic.V(dt_name) <= logic.S(
273+
pg_funcs.cast(end, "timestamptz")
274+
)
259275

260276
elif not end:
261-
return logic.V(dt_name) >= logic.S(pg_funcs.cast(start, "timestamptz"))
277+
return logic.V(dt_name) >= logic.S(
278+
pg_funcs.cast(start, "timestamptz")
279+
)
262280

263281
else:
264282
return pg_funcs.AND(
265-
logic.V(dt_name) >= logic.S(pg_funcs.cast(start, "timestamptz")),
266-
logic.V(dt_name) < logic.S(pg_funcs.cast(end, "timestamptz")),
283+
logic.V(dt_name)
284+
>= logic.S(pg_funcs.cast(start, "timestamptz")),
285+
logic.V(dt_name)
286+
< logic.S(pg_funcs.cast(end, "timestamptz")),
267287
)
268288

269289
def _features_query(
@@ -342,7 +362,9 @@ async def query(
342362
) -> Tuple[FeatureCollection, int]:
343363
"""Build and run Pg query."""
344364
if geom and geom.lower() != "none" and not self.geometry_column(geom):
345-
raise InvalidGeometryColumnName(f"Invalid Geometry Column: {geom}.")
365+
raise InvalidGeometryColumnName(
366+
f"Invalid Geometry Column: {geom}."
367+
)
346368

347369
sql_query = """
348370
WITH
@@ -460,7 +482,9 @@ async def feature(
460482
def queryables(self) -> Dict:
461483
"""Return the queryables."""
462484
geoms = {
463-
col.name: {"$ref": geojson_schema.get(col.geometry_type.upper(), "")}
485+
col.name: {
486+
"$ref": geojson_schema.get(col.geometry_type.upper(), "")
487+
}
464488
for col in self.geometry_columns
465489
}
466490
props = {

0 commit comments

Comments
 (0)