Skip to content

Commit c8c8819

Browse files
author
Phil Varner
authored
fix search, next, and prev media types (#393)
* update root POST /search link, next, and prev links to use application/geojson instead of application/json * pre-commit fixup
1 parent 06f610e commit c8c8819

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ def link_next(self) -> Optional[Dict[str, Any]]:
125125
href = merge_params(self.url, {"token": f"next:{self.next}"})
126126
link = dict(
127127
rel=Relations.next.value,
128-
type=MimeTypes.json.value,
128+
type=MimeTypes.geojson.value,
129129
method=method,
130130
href=href,
131131
)
132132
return link
133133
if method == "POST":
134134
return {
135135
"rel": Relations.next,
136-
"type": MimeTypes.json,
136+
"type": MimeTypes.geojson,
137137
"method": method,
138138
"href": f"{self.request.url}",
139139
"body": {**self.request.postbody, "token": f"next:{self.next}"},
@@ -149,14 +149,14 @@ def link_prev(self) -> Optional[Dict[str, Any]]:
149149
href = merge_params(self.url, {"token": f"prev:{self.prev}"})
150150
return dict(
151151
rel=Relations.previous.value,
152-
type=MimeTypes.json.value,
152+
type=MimeTypes.geojson.value,
153153
method=method,
154154
href=href,
155155
)
156156
if method == "POST":
157157
return {
158158
"rel": Relations.previous,
159-
"type": MimeTypes.json,
159+
"type": MimeTypes.geojson,
160160
"method": method,
161161
"href": f"{self.request.url}",
162162
"body": {**self.request.postbody, "token": f"prev:{self.prev}"},

stac_fastapi/pgstac/tests/resources/test_conformance.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import urllib.parse
2+
from typing import Dict, Optional
23

34
import pytest
45

@@ -9,13 +10,18 @@ async def response(app_client):
910

1011

1112
@pytest.fixture(scope="module")
12-
async def response_json(response):
13+
async def response_json(response) -> Dict:
1314
return response.json()
1415

1516

16-
def get_link(landing_page, rel_type):
17+
def get_link(landing_page, rel_type, method: Optional[str] = None):
1718
return next(
18-
filter(lambda link: link["rel"] == rel_type, landing_page["links"]), None
19+
filter(
20+
lambda link: link["rel"] == rel_type
21+
and (not method or link.get("method") == method),
22+
landing_page["links"],
23+
),
24+
None,
1925
)
2026

2127

@@ -41,7 +47,7 @@ def test_landing_page_health(response):
4147
@pytest.mark.asyncio
4248
@pytest.mark.parametrize("rel_type,expected_media_type,expected_path", link_tests)
4349
async def test_landing_page_links(
44-
response_json, app_client, rel_type, expected_media_type, expected_path
50+
response_json: Dict, app_client, rel_type, expected_media_type, expected_path
4551
):
4652
link = get_link(response_json, rel_type)
4753

@@ -59,11 +65,13 @@ async def test_landing_page_links(
5965
# code here seems meaningless since it would be the same as if the endpoint did not exist. Once
6066
# https://github.com/stac-utils/stac-fastapi/pull/227 has been merged we can add this to the
6167
# parameterized tests above.
62-
def test_search_link(response_json):
63-
search_link = get_link(response_json, "search")
64-
65-
assert search_link is not None
66-
assert search_link.get("type") == "application/geo+json"
67-
68-
search_path = urllib.parse.urlsplit(search_link.get("href")).path
69-
assert search_path == "/search"
68+
def test_search_link(response_json: Dict):
69+
for search_link in [
70+
get_link(response_json, "search", "GET"),
71+
get_link(response_json, "search", "POST"),
72+
]:
73+
assert search_link is not None
74+
assert search_link.get("type") == "application/geo+json"
75+
76+
search_path = urllib.parse.urlsplit(search_link.get("href")).path
77+
assert search_path == "/search"

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _landing_page(
278278
},
279279
{
280280
"rel": Relations.search.value,
281-
"type": MimeTypes.json,
281+
"type": MimeTypes.geojson,
282282
"title": "STAC search",
283283
"href": urljoin(base_url, "search"),
284284
"method": "POST",

0 commit comments

Comments
 (0)