Skip to content

Commit 31c954c

Browse files
committed
feat: check conformance before search links
This allows use to provide a more meaningful error message when, e.g., folks try to search a static catalog.
1 parent dfab362 commit 31c954c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pystac_client/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def search(self, **kwargs: Any) -> ItemSearch:
170170
<https://github.com/radiantearth/stac-api-spec/tree/master/item-search>`__ or does not have a link with
171171
a ``"rel"`` type of ``"search"``.
172172
"""
173+
if not self._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH):
174+
raise NotImplementedError("This catalog does not support search because it "
175+
f"does not conform to \"{ConformanceClasses.ITEM_SEARCH}\"")
173176
search_link = self.get_search_link()
174177
if search_link is None:
175178
raise NotImplementedError(

tests/test_client.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import json
2+
import os.path
13
from datetime import datetime
4+
from tempfile import TemporaryDirectory
25
from urllib.parse import urlsplit, parse_qs
36

47
from dateutil.tz import tzutc
@@ -307,6 +310,20 @@ def test_no_search_link(self, api):
307310
api.search(limit=10, max_items=10, collections='naip')
308311
assert 'No link with "rel" type of "search"' in str(excinfo.value)
309312

313+
def test_no_conforms_to(self):
314+
with open(str(TEST_DATA / 'planetary-computer-root.json')) as f:
315+
data = json.load(f)
316+
del data["conformsTo"]
317+
with TemporaryDirectory() as temporary_directory:
318+
path = os.path.join(temporary_directory, "catalog.json")
319+
with open(path, "w") as f:
320+
json.dump(data, f)
321+
api = Client.from_file(path)
322+
323+
with pytest.raises(NotImplementedError) as excinfo:
324+
api.search(limit=10, max_items=10, collections='naip')
325+
assert 'does not support search' in str(excinfo.value)
326+
310327
def test_search(self, api):
311328
results = api.search(bbox=[-73.21, 43.99, -73.12, 44.05],
312329
collections='naip',

0 commit comments

Comments
 (0)