Skip to content

Commit 51ac649

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
test: add STAC_ITEM_LIMIT env var tests for results limiting
Add tests to verify the STAC_ITEM_LIMIT environment variable correctly limits returned items in all the following endpoints: - Collections list (`/collections`) - Search results (`/search`) - Collection items (`/collections/{id}/items`) Ensures the pagination and result limiting behaves as expected in the API.
1 parent b4397fb commit 51ac649

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

stac_fastapi/tests/api/test_api.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,3 +1470,73 @@ def create_items(date_prefix: str, start_day: int, count: int) -> dict:
14701470
f"/collections/{collection_id}/items/{base_item['id']}", json=item_data
14711471
)
14721472
assert response.json()["properties"]["platform"] == "Updated platform via PUT"
1473+
1474+
1475+
@pytest.mark.asyncio
1476+
async def test_collections_limit_env_variable(app_client, txn_client, load_test_data):
1477+
limit = "5"
1478+
os.environ["STAC_ITEM_LIMIT"] = limit
1479+
item = load_test_data("test_collection.json")
1480+
1481+
for i in range(10):
1482+
test_collection = item.copy()
1483+
test_collection["id"] = f"test-collection-env-{i}"
1484+
test_collection["title"] = f"Test Collection Env {i}"
1485+
await create_collection(txn_client, test_collection)
1486+
1487+
resp = await app_client.get("/collections")
1488+
assert resp.status_code == 200
1489+
resp_json = resp.json()
1490+
assert int(limit) == len(resp_json["collections"])
1491+
1492+
1493+
@pytest.mark.asyncio
1494+
async def test_search_collection_limit_env_variable(
1495+
app_client, txn_client, load_test_data
1496+
):
1497+
limit = "5"
1498+
os.environ["STAC_ITEM_LIMIT"] = limit
1499+
1500+
test_collection = load_test_data("test_collection.json")
1501+
test_collection_id = "test-collection-search-limit"
1502+
test_collection["id"] = test_collection_id
1503+
await create_collection(txn_client, test_collection)
1504+
1505+
item = load_test_data("test_item.json")
1506+
item["collection"] = test_collection_id
1507+
1508+
for i in range(10):
1509+
test_item = item.copy()
1510+
test_item["id"] = f"test-item-search-{i}"
1511+
await create_item(txn_client, test_item)
1512+
1513+
resp = await app_client.get("/search", params={"collections": [test_collection_id]})
1514+
assert resp.status_code == 200
1515+
resp_json = resp.json()
1516+
assert int(limit) == len(resp_json["features"])
1517+
1518+
1519+
@pytest.mark.asyncio
1520+
async def test_collection_items_limit_env_variable(
1521+
app_client, txn_client, load_test_data
1522+
):
1523+
limit = "5"
1524+
os.environ["STAC_ITEM_LIMIT"] = limit
1525+
1526+
test_collection = load_test_data("test_collection.json")
1527+
test_collection_id = "test-collection-items-limit"
1528+
test_collection["id"] = test_collection_id
1529+
await create_collection(txn_client, test_collection)
1530+
1531+
item = load_test_data("test_item.json")
1532+
item["collection"] = test_collection_id
1533+
1534+
for i in range(10):
1535+
test_item = item.copy()
1536+
test_item["id"] = f"test-item-collection-{i}"
1537+
await create_item(txn_client, test_item)
1538+
1539+
resp = await app_client.get(f"/collections/{test_collection_id}/items")
1540+
assert resp.status_code == 200
1541+
resp_json = resp.json()
1542+
assert int(limit) == len(resp_json["features"])

0 commit comments

Comments
 (0)