Skip to content

Commit b0362b7

Browse files
authored
Merge pull request #244 from stac-utils/pag-links-test
Add pagination test to verify the absence of a 'next' link on the last page of results
2 parents 8660a13 + e17162b commit b0362b7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- A test to ensure that pagination correctly returns expected links, particularly verifying the absence of a 'next' link on the last page of results [#244](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/244)
13+
1014
### Fixed
1115

1216
- Fixed issue where searches return an empty `links` array [#241](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/241)

stac_fastapi/tests/resources/test_item.py

+42
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,48 @@ async def test_pagination_base_links(app_client, ctx):
579579
assert {"self", "root"}.issubset({link["rel"] for link in page_data["links"]})
580580

581581

582+
@pytest.mark.asyncio
583+
async def test_pagination_links_behavior(app_client, ctx, txn_client):
584+
"""Test the links in pagination specifically look for last page behavior."""
585+
586+
# Ingest 5 items
587+
for _ in range(5):
588+
ctx.item["id"] = str(uuid.uuid4())
589+
await create_item(txn_client, item=ctx.item)
590+
591+
# Setting a limit to ensure the creation of multiple pages
592+
limit = 1
593+
first_page = await app_client.get(
594+
f"/collections/{ctx.item['collection']}/items?limit={limit}"
595+
)
596+
first_page_data = first_page.json()
597+
598+
# Test for 'next' link in the first page
599+
next_link = next(
600+
(link for link in first_page_data["links"] if link["rel"] == "next"), None
601+
)
602+
assert next_link, "Missing 'next' link on the first page"
603+
604+
# Follow to the last page using 'next' links
605+
current_page_data = first_page_data
606+
while "next" in {link["rel"] for link in current_page_data["links"]}:
607+
next_page_url = next(
608+
(
609+
link["href"]
610+
for link in current_page_data["links"]
611+
if link["rel"] == "next"
612+
),
613+
None,
614+
)
615+
next_page = await app_client.get(next_page_url)
616+
current_page_data = next_page.json()
617+
618+
# Verify the last page does not have a 'next' link
619+
assert "next" not in {
620+
link["rel"] for link in current_page_data["links"]
621+
}, "Unexpected 'next' link on the last page"
622+
623+
582624
@pytest.mark.asyncio
583625
async def test_pagination_item_collection(app_client, ctx, txn_client):
584626
"""Test item collection pagination links (paging extension)"""

0 commit comments

Comments
 (0)