Skip to content

Commit 6dea715

Browse files
committed
update pagination test
1 parent d167a29 commit 6dea715

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

stac_fastapi/tests/api/test_api_search_collections.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -787,28 +787,43 @@ async def test_collections_pagination_all_endpoints(app_client, txn_client, ctx)
787787
for i, expected_id in enumerate(expected_ids):
788788
assert test_found[i]["id"] == expected_id
789789

790-
# Test second page using the token from the first page
791-
if "token" in resp_json and resp_json["token"]:
792-
token = resp_json["token"]
793-
794-
# Make the request with token
790+
# Test second page using the token from the next link
791+
next_link = None
792+
for link in resp_json.get("links", []):
793+
if link.get("rel") == "next":
794+
next_link = link
795+
break
796+
797+
if next_link:
798+
# Extract token based on method
795799
if endpoint["method"] == "GET":
796-
params = [(endpoint["param"], str(limit)), ("token", token)]
797-
resp = await app_client.get(endpoint["path"], params=params)
800+
# For GET, token is in the URL query params
801+
from urllib.parse import parse_qs, urlparse
802+
803+
parsed_url = urlparse(next_link["href"])
804+
query_params = parse_qs(parsed_url.query)
805+
token = query_params.get("token", [None])[0]
806+
807+
if token:
808+
params = [(endpoint["param"], str(limit)), ("token", token)]
809+
resp = await app_client.get(endpoint["path"], params=params)
810+
else:
811+
continue # Skip if no token found
798812
else: # POST
799-
body = {endpoint["body_key"]: limit, "token": token}
800-
resp = await app_client.post(endpoint["path"], json=body)
813+
# For POST, token is in the body
814+
body = next_link.get("body", {})
815+
if "token" in body:
816+
resp = await app_client.post(endpoint["path"], json=body)
817+
else:
818+
continue # Skip if no token found
801819

802820
assert (
803821
resp.status_code == 200
804822
), f"Failed for {endpoint['method']} {endpoint['path']} with token"
805823
resp_json = resp.json()
806824

807825
# Filter to our test collections
808-
if endpoint["path"] == "/collections":
809-
found_collections = resp_json
810-
else: # For collection-search endpoints
811-
found_collections = resp_json["collections"]
826+
found_collections = resp_json["collections"]
812827

813828
test_found = [
814829
c for c in found_collections if c["id"].startswith(test_prefix)

0 commit comments

Comments
 (0)