Skip to content

Commit 90cccc9

Browse files
committed
add test
1 parent a4db2cf commit 90cccc9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

stac_fastapi/elasticsearch/tests/resources/test_collection.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pystac
2-
2+
import pytest
3+
import uuid
4+
from ..conftest import create_collection
35

46
async def test_create_and_delete_collection(app_client, load_test_data):
57
"""Test creation and deletion of a collection"""
@@ -70,3 +72,39 @@ async def test_returns_valid_collection(ctx, app_client):
7072
resp_json, root=mock_root, preserve_dict=False
7173
)
7274
collection.validate()
75+
76+
@pytest.mark.asyncio
77+
async def test_pagination_collection(app_client, ctx, txn_client):
78+
"""Test collection pagination links"""
79+
ids = [ctx.collection["id"]]
80+
81+
# Ingest 5 collections
82+
for _ in range(5):
83+
ctx.collection["id"] = str(uuid.uuid4())
84+
await create_collection(txn_client, collection=ctx.collection)
85+
ids.append(ctx.collection["id"])
86+
87+
# Paginate through all 6 collections with a limit of 1 (expecting 7 requests)
88+
page = await app_client.get(
89+
f"/collections", params={"limit": 1}
90+
)
91+
92+
collection_ids = []
93+
idx = 0
94+
for idx in range(100):
95+
page_data = page.json()
96+
next_link = list(filter(lambda link: link["rel"] == "next", page_data["links"]))
97+
if not next_link:
98+
assert not page_data["collections"]
99+
break
100+
101+
assert len(page_data["collections"]) == 1
102+
collection_ids.append(page_data["collections"][0]["id"])
103+
104+
href = next_link[0]["href"][len("http://test-server") :]
105+
page = await app_client.get(href)
106+
107+
assert idx == len(ids)
108+
109+
# Confirm we have paginated through all collections
110+
assert not set(collection_ids) - set(ids)

0 commit comments

Comments
 (0)