Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check conformance before search links #164

Merged
merged 2 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- lru_cache to several methods [#167](https://github.com/stac-utils/pystac-client/pull/167)

### Changed

- Better error message when trying to search a non-item-search-conforming catalog [#164](https://github.com/stac-utils/pystac-client/pull/164)

## [v0.3.4] - 2022-05-18

### Changed
Expand Down
3 changes: 3 additions & 0 deletions pystac_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def search(self, **kwargs: Any) -> ItemSearch:
<https://github.com/radiantearth/stac-api-spec/tree/master/item-search>`__ or does not have a link with
a ``"rel"`` type of ``"search"``.
"""
if not self._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH):
raise NotImplementedError("This catalog does not support search because it "
f"does not conform to \"{ConformanceClasses.ITEM_SEARCH}\"")
search_link = self.get_search_link()
if search_link is None:
raise NotImplementedError(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json
import os.path
from datetime import datetime
from tempfile import TemporaryDirectory
from urllib.parse import urlsplit, parse_qs

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

def test_no_conforms_to(self):
with open(str(TEST_DATA / 'planetary-computer-root.json')) as f:
data = json.load(f)
del data["conformsTo"]
with TemporaryDirectory() as temporary_directory:
path = os.path.join(temporary_directory, "catalog.json")
with open(path, "w") as f:
json.dump(data, f)
api = Client.from_file(path)
gadomski marked this conversation as resolved.
Show resolved Hide resolved

with pytest.raises(NotImplementedError) as excinfo:
api.search(limit=10, max_items=10, collections='naip')
assert 'does not support search' in str(excinfo.value)

def test_search(self, api):
results = api.search(bbox=[-73.21, 43.99, -73.12, 44.05],
collections='naip',
Expand Down