|
1 | 1 | import pystac |
2 | | - |
| 2 | +import pytest |
| 3 | +import uuid |
| 4 | +from ..conftest import create_collection |
3 | 5 |
|
4 | 6 | async def test_create_and_delete_collection(app_client, load_test_data): |
5 | 7 | """Test creation and deletion of a collection""" |
@@ -70,3 +72,39 @@ async def test_returns_valid_collection(ctx, app_client): |
70 | 72 | resp_json, root=mock_root, preserve_dict=False |
71 | 73 | ) |
72 | 74 | 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