Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 1cdc145

Browse files
fix: fix bug in get_products where end was not being propery calculated by being calculated before new start index
1 parent e562d56 commit 1cdc145

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/stapi_fastapi/routers/root_router.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,13 @@ def get_products(
145145
) -> ProductsCollection:
146146
start = 0
147147
product_ids = [*self.product_routers.keys()]
148-
end = min(start + limit, len(product_ids))
149148
try:
150149
if next:
151150
start = product_ids.index(next)
152151
except ValueError:
153152
logging.exception("An error occurred while retrieving orders")
154153
raise NotFoundException(detail="Error finding pagination token") from None
155-
154+
end = min(start + limit, len(product_ids))
156155
ids = product_ids[start:end]
157156
links = [
158157
Link(

tests/test_product.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@ def test_product_pagination(stapi_client: TestClient, limit: int):
7171
assert res.status_code == status.HTTP_200_OK
7272
body = res.json()
7373
assert len(body["products"]) == limit
74+
links = body["links"]
7475
for d in body["links"]:
7576
if ("rel", "next") in d.items():
7677
next = d["href"]
7778

78-
while len(body["links"]) > 1:
79+
while len(links) > 1:
7980
res = stapi_client.get(next)
8081
assert res.status_code == status.HTTP_200_OK
8182
body = res.json()
82-
assert len(body["products"]) == limit
83+
assert body["products"] != []
84+
links = body["links"]
8385
for d in body["links"]:
8486
if ("rel", "next") in d.items():
87+
assert len(body["products"]) == limit
8588
next = body["links"][0]["href"]
8689

8790

0 commit comments

Comments
 (0)