Skip to content

Commit 000b547

Browse files
Merge branch 'main' into fix/network-request-during-test
2 parents ff63605 + e41c7e8 commit 000b547

File tree

9 files changed

+1389
-17
lines changed

9 files changed

+1389
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9-
### Developer
9+
### Added
1010

1111
- Adds `--block-network` option to all test commands to ensure no network requests are made during unit tests
1212
[#119](https://github.com/stac-utils/pystac-client/pull/119)
1313

14+
### Fixed
15+
16+
- `Client.get_collections` raised an exception when API did not publish `/collections` conformance class instead of falling back to using child links
17+
[#120](https://github.com/stac-utils/pystac-client/pull/120)
18+
1419
## [0.3.0] - 2021-09-28
1520

1621
### Added

pystac_client/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_collections(self) -> Iterable[CollectionClient]:
9494
Return:
9595
Iterable[CollectionClient]: Iterator through Collections in Catalog/API
9696
"""
97-
if self._stac_io.assert_conforms_to(ConformanceClasses.COLLECTIONS):
97+
if self._stac_io.conforms_to(ConformanceClasses.COLLECTIONS):
9898
url = self.get_self_href() + '/collections'
9999
for page in self._stac_io.get_pages(url):
100100
if 'collections' not in page:
@@ -111,7 +111,7 @@ def get_items(self) -> Iterable["Item_Type"]:
111111
Return:
112112
Iterable[Item]:: Generator of items whose parent is this catalog.
113113
"""
114-
if self._stac_io.assert_conforms_to(ConformanceClasses.ITEM_SEARCH):
114+
if self._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH):
115115
search = self.search()
116116
yield from search.get_items()
117117
else:
@@ -126,7 +126,7 @@ def get_all_items(self) -> Iterable["Item_Type"]:
126126
catalogs or collections connected to this catalog through
127127
child links.
128128
"""
129-
if self._stac_io.assert_conforms_to(ConformanceClasses.ITEM_SEARCH):
129+
if self._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH):
130130
yield from self.get_items()
131131
else:
132132
yield from super().get_items()

pystac_client/stac_api_io.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,16 @@ def get_pages(self, url, method='GET', parameters={}) -> Iterator[Dict]:
210210
next_link = next((link for link in page.get('links', []) if link['rel'] == 'next'),
211211
None)
212212

213-
def assert_conforms_to(self, conformance_class: ConformanceClasses):
214-
"""Whether the API conforms to the given standard. This method only checks against the ``"conformsTo"``
215-
property from the API landing page and does not make any additional calls to a ``/conformance`` endpoint
216-
even if the API provides such an endpoint.
213+
def assert_conforms_to(self, conformance_class: ConformanceClasses) -> None:
214+
"""Raises a :exc:`NotImplementedError` if the API does not publish the given conformance class. This method
215+
only checks against the ``"conformsTo"`` property from the API landing page and does not make any additional
216+
calls to a ``/conformance`` endpoint even if the API provides such an endpoint.
217217
218218
Args:
219-
key: The ``ConformanceClasses`` key to check conformance against.
220-
221-
Return:
222-
bool: Indicates if the API conforms to the given spec or URI.
219+
conformance_class: The ``ConformanceClasses`` key to check conformance against.
223220
"""
224221
if not self.conforms_to(conformance_class):
225222
raise NotImplementedError(f"{conformance_class} not supported")
226-
else:
227-
return True
228223

229224
def conforms_to(self, conformance_class: ConformanceClasses) -> bool:
230225
"""Whether the API conforms to the given standard. This method only checks against the ``"conformsTo"``

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pytest-cov~=2.11.1
77
pytest-recording~=0.11.0
88
pytest-console-scripts~=1.1.0
99
recommonmark~=0.7.1
10+
requests-mock~=1.9.3
1011
Sphinx~=3.5.1
1112
toml~=0.10.2
1213
yapf==0.30.*

tests/cassettes/test_client/TestAPI.test_collections_fallback.yaml

Lines changed: 870 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)