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

Terminate on empty page #338

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Python 3.11 support [#347](https://github.com/stac-utils/pystac-client/pull/347)
- `request_modifier` to `StacApiIO` to allow for additional authentication mechanisms (e.g. AWS SigV4) [#371](https://github.com/stac-utils/pystac-client/issues/371)
- *Authentication* tutorial, demonstrating how to use to the provided hooks to use both basic and AWS SigV4 authentication [#371](https://github.com/stac-utils/pystac-client/issues/371)
- `request_modifier` to `StacApiIO` to allow for additional authentication mechanisms (e.g. AWS SigV4) [#372](https://github.com/stac-utils/pystac-client/pull/372)
- *Authentication* tutorial, demonstrating how to use to the provided hooks to use both basic and AWS SigV4 authentication [#372](https://github.com/stac-utils/pystac-client/pull/372)
- CI checks for Windows and MacOS [#378](https://github.com/stac-utils/pystac-client/pull/378)

### Changed

### Fixed

- Stop iteration on an empty page [#338](https://github.com/stac-utils/pystac-client/pull/338)
- Some mishandled cases for datetime intervals [#363](https://github.com/stac-utils/pystac-client/pull/363)
- Collection requests when the Client's url ends in a '/' [#373](https://github.com/stac-utils/pystac-client/pull/373), [#405](https://github.com/stac-utils/pystac-client/pull/405)
- Parse datetimes more strictly [#364](https://github.com/stac-utils/pystac-client/pull/364)
Expand Down
2 changes: 2 additions & 0 deletions pystac_client/stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def get_pages(
while next_link:
link = Link.from_dict(next_link)
page = self.read_json(link, parameters=parameters)
if not page.get("features", False):
return None
yield page

# get the next link and make the next request
Expand Down
73 changes: 73 additions & 0 deletions tests/test_stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,76 @@ def test_write(self, tmp_path: Path) -> None:
with open(test_file) as file:
data = file.read()
assert data == "Hi there!"

def test_stop_on_empty_page(self, requests_mock: Mocker) -> None:
requests_mock.get(
"https://pystac-client.test/search",
status_code=200,
json={
"features": [{"foo": "bar"}],
"links": [
{
"rel": "next",
"href": "https://pystac-client.test/search?token=baz",
}
],
},
)
requests_mock.get(
"https://pystac-client.test/search?token=baz",
status_code=200,
json={
"features": [],
"links": [
{
"rel": "next",
"href": "https://pystac-client.test/search?token=baw",
}
],
},
)
requests_mock.get(
"https://pystac-client.test/search?token=baw",
status_code=500,
json={},
)
stac_api_io = StacApiIO()
pages = list(stac_api_io.get_pages("https://pystac-client.test/search"))
assert len(pages) == 1
assert pages[0]["features"][0]["foo"] == "bar"

def test_stop_on_featureless_page(self, requests_mock: Mocker) -> None:
requests_mock.get(
"https://pystac-client.test/search",
status_code=200,
json={
"features": [{"foo": "bar"}],
"links": [
{
"rel": "next",
"href": "https://pystac-client.test/search?token=baz",
}
],
},
)
requests_mock.get(
"https://pystac-client.test/search?token=baz",
status_code=200,
json={
"links": [
{
"rel": "next",
"href": "https://pystac-client.test/search?token=baw",
}
],
},
)
requests_mock.get(
"https://pystac-client.test/search?token=baw",
status_code=500,
json={},
)
stac_api_io = StacApiIO()
pages = list(stac_api_io.get_pages("https://pystac-client.test/search"))
assert len(pages) == 1
assert pages[0]["features"][0]["foo"] == "bar"