Skip to content

Commit

Permalink
Double pagination of Chains (#1253)
Browse files Browse the repository at this point in the history
Doubles the `max_limit`/`default_limit` of `Chains` to 40:

- Set `max_limit`/`default_limit` to 40
- Update tests accordingly
  • Loading branch information
iamacook authored Oct 8, 2024
1 parent 0c9b958 commit a2c2c31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/chains/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ def test_json_payload_format(self) -> None:

class ChainPaginationViewTests(APITestCase):
def test_pagination_next_page(self) -> None:
ChainFactory.create_batch(21)
ChainFactory.create_batch(41)
url = reverse("v1:chains:list")

response = self.client.get(path=url, data=None, format="json")

self.assertEqual(response.status_code, 200)
# number of items should be equal to the number of total items
self.assertEqual(response.json()["count"], 21)
self.assertEqual(response.json()["count"], 41)
self.assertEqual(
response.json()["next"],
"http://testserver/api/v1/chains/?limit=20&offset=20",
"http://testserver/api/v1/chains/?limit=40&offset=40",
)
self.assertEqual(response.json()["previous"], None)
# returned items should be equal to max_limit
self.assertEqual(len(response.json()["results"]), 20)
self.assertEqual(len(response.json()["results"]), 40)

def test_request_more_than_max_limit_should_return_max_limit(self) -> None:
ChainFactory.create_batch(101)
Expand All @@ -145,25 +145,25 @@ def test_request_more_than_max_limit_should_return_max_limit(self) -> None:
self.assertEqual(response.json()["count"], 101)
self.assertEqual(
response.json()["next"],
"http://testserver/api/v1/chains/?limit=20&offset=20",
"http://testserver/api/v1/chains/?limit=40&offset=40",
)
self.assertEqual(response.json()["previous"], None)
# returned items should still be equal to max_limit
self.assertEqual(len(response.json()["results"]), 20)
self.assertEqual(len(response.json()["results"]), 40)

def test_offset_greater_than_count(self) -> None:
ChainFactory.create_batch(21)
ChainFactory.create_batch(41)
# requesting offset of number of chains
url = reverse("v1:chains:list") + f'{"?offset=21"}'
url = reverse("v1:chains:list") + f'{"?offset=41"}'

response = self.client.get(path=url, data=None, format="json")

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["count"], 21)
self.assertEqual(response.json()["count"], 41)
self.assertEqual(response.json()["next"], None)
self.assertEqual(
response.json()["previous"],
"http://testserver/api/v1/chains/?limit=20&offset=1",
"http://testserver/api/v1/chains/?limit=40&offset=1",
)
# returned items should still be zero
self.assertEqual(len(response.json()["results"]), 0)
Expand Down
4 changes: 2 additions & 2 deletions src/chains/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


class ChainsPagination(LimitOffsetPagination):
default_limit = 20
max_limit = 20
default_limit = 40
max_limit = 40


class ChainsListView(ListAPIView): # type: ignore[type-arg]
Expand Down

0 comments on commit a2c2c31

Please sign in to comment.