Skip to content

Commit c42a3d7

Browse files
committed
add tests
1 parent 5eedf64 commit c42a3d7

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

tests/routes/test_collections.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_collections(app):
1919

2020

2121
def test_collections_landsat(app):
22-
"""Test /collections endpoint."""
22+
"""Test /collections/{collectionId} endpoint."""
2323
response = app.get("/collections/public.landsat_wrs")
2424
assert response.status_code == 200
2525
assert response.headers["content-type"] == "application/json"
@@ -44,3 +44,19 @@ def test_collections_landsat(app):
4444
assert response.status_code == 422
4545
body = response.json()
4646
assert body["detail"] == "Invalid Table format 'landsat_wrs'."
47+
48+
49+
def test_collections_queryables(app):
50+
"""Test /collections/{collectionId}/queryables endpoint."""
51+
response = app.get("/collections/public.landsat_wrs/queryables")
52+
assert response.status_code == 200
53+
assert response.headers["content-type"] == "application/schema+json"
54+
body = response.json()
55+
assert body["title"] == "public.landsat_wrs"
56+
assert body["type"] == "object"
57+
assert ["title", "properties", "type", "$schema", "$id"] == list(body)
58+
59+
response = app.get("/collections/public.landsat_wrs/queryables?f=html")
60+
assert response.status_code == 200
61+
assert "text/html" in response.headers["content-type"]
62+
assert "Queryables" in response.text

tifeatures/dbmodel.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@ class Column(BaseModel):
1414
description: Optional[str]
1515

1616
@property
17-
def json_type(self):
17+
def json_type(self) -> str:
1818
"""Return JSON field type."""
19-
type = self.type
19+
pgtype = self.type
20+
2021
if any(
2122
[
22-
type.startswith("int"),
23-
type.startswith("num"),
24-
type.startswith("float"),
23+
pgtype.startswith("int"),
24+
pgtype.startswith("num"),
25+
pgtype.startswith("float"),
2526
]
2627
):
2728
return "number"
28-
if type.startswith("bool"):
29+
30+
if pgtype.startswith("bool"):
2931
return "boolean"
30-
if type.endswith("[]"):
32+
33+
if pgtype.endswith("[]"):
3134
return "array"
32-
if any([type.startswith("json"), type.startswith("geo")]):
35+
36+
if any([pgtype.startswith("json"), pgtype.startswith("geo")]):
3337
return "object"
38+
3439
return "string"
3540

3641

tifeatures/factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from tifeatures.layer import CollectionLayer
2222
from tifeatures.layer import Table as TableLayer
2323
from tifeatures.resources.enums import MediaType, ResponseType
24-
from tifeatures.resources.response import GeoJSONResponse
24+
from tifeatures.resources.response import GeoJSONResponse, SchemaJSONResponse
2525
from tifeatures.settings import APISettings
2626

2727
from fastapi import APIRouter, Depends, Path, Query
@@ -438,6 +438,7 @@ def collection(
438438
response_model=model.Queryables,
439439
response_model_exclude_none=True,
440440
response_model_by_alias=True,
441+
response_class=SchemaJSONResponse,
441442
responses={
442443
200: {
443444
"content": {

tifeatures/resources/response.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ class GeoJSONResponse(responses.JSONResponse):
77
"""GeoJSON Response"""
88

99
media_type = "application/geo+json"
10+
11+
12+
class SchemaJSONResponse(responses.JSONResponse):
13+
"""Schema Response"""
14+
15+
media_type = "application/schema+json"

0 commit comments

Comments
 (0)