Skip to content

Commit

Permalink
add pagination links behavior test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 committed May 9, 2024
1 parent 3dbf21d commit c3e6633
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions stac_fastapi/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,48 @@ async def test_pagination_post(app_client, ctx, txn_client):
assert not set(retrieved_item_ids) - set(expected_item_ids)


@pytest.mark.asyncio
async def test_pagination_links_behavior(app_client, ctx, txn_client):
"""Test the links in pagination specifically look for last page behavior."""

# Ingest 5 items
for _ in range(5):
ctx.item["id"] = str(uuid.uuid4())
await create_item(txn_client, item=ctx.item)

# Setting a limit to ensure the creation of multiple pages
limit = 1
first_page = await app_client.get(
f"/collections/{ctx.item['collection']}/items?limit={limit}"
)
first_page_data = first_page.json()

# Test for 'next' link in the first page
next_link = next(
(link for link in first_page_data["links"] if link["rel"] == "next"), None
)
assert next_link, "Missing 'next' link on the first page"

# Follow to the last page using 'next' links
current_page_data = first_page_data
while "next" in {link["rel"] for link in current_page_data["links"]}:
next_page_url = next(
(
link["href"]
for link in current_page_data["links"]
if link["rel"] == "next"
),
None,
)
next_page = await app_client.get(next_page_url)
current_page_data = next_page.json()

# Verify the last page does not have a 'next' link
assert "next" not in {
link["rel"] for link in current_page_data["links"]
}, "Unexpected 'next' link on the last page"


@pytest.mark.asyncio
async def test_pagination_token_idempotent(app_client, ctx, txn_client):
"""Test that pagination tokens are idempotent (paging extension)"""
Expand Down

0 comments on commit c3e6633

Please sign in to comment.