Skip to content

Commit 22cf0fc

Browse files
update test for cursor based pagination
1 parent f3753b3 commit 22cf0fc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

tests/test_product.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ def test_products_pagination(self, create_product):
222222
assert len(data1["products"]) == 10
223223

224224
# Page 2
225-
resp2 = self.client.get("/products?page=2")
225+
next_cursor = data1["cursor"]["next"]
226+
resp2 = self.client.get(f"/products?cursor={next_cursor}")
226227
assert resp2.status_code == 200
227228
data2 = resp2.get_json()
228229
assert "products" in data2

tests/test_relationships.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ def test_get_category_products_populated_with_pagination(self, create_category,
218218
product_resp = create_product(f"P{index}", "desc", subcategories=[subcategory["id"]])
219219
product_ids.add(product_resp.get_json().get("id"))
220220

221-
page1 = self.client.get(f"/categories/{category['id']}/products?page=1").get_json()
222-
page2 = self.client.get(f"/categories/{category['id']}/products?page=2").get_json()
221+
page1 = self.client.get(f"/categories/{category['id']}/products").get_json()
222+
next_cursor = page1["cursor"]["next"]
223+
page2 = self.client.get(f"/categories/{category['id']}/products?cursor={next_cursor}").get_json()
223224
assert len(page1["products"]) == 10
224225
assert len(page2["products"]) == 2
225226

@@ -253,7 +254,8 @@ def test_get_subcategory_products_populated_with_pagination(self, create_subcate
253254
product_ids.add(product_resp.get_json().get("id"))
254255

255256
page1 = self.client.get(f"/subcategories/{subcategory['id']}/products?page=1").get_json()
256-
page2 = self.client.get(f"/subcategories/{subcategory['id']}/products?page=2").get_json()
257+
next_cursor = page1["cursor"]["next"]
258+
page2 = self.client.get(f"/subcategories/{subcategory['id']}/products?cursor={next_cursor}").get_json()
257259
assert len(page1["products"]) == 10
258260
assert len(page2["products"]) == 1
259261

0 commit comments

Comments
 (0)