From a2c2c31848b196a43b120d2a9e9fa57720c99f30 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Tue, 8 Oct 2024 15:28:24 +0200 Subject: [PATCH] Double pagination of `Chains` (#1253) Doubles the `max_limit`/`default_limit` of `Chains` to 40: - Set `max_limit`/`default_limit` to 40 - Update tests accordingly --- src/chains/tests/test_views.py | 20 ++++++++++---------- src/chains/views.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/chains/tests/test_views.py b/src/chains/tests/test_views.py index 2deddf2f..3ce5fecc 100644 --- a/src/chains/tests/test_views.py +++ b/src/chains/tests/test_views.py @@ -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) @@ -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) diff --git a/src/chains/views.py b/src/chains/views.py index b502e03e..f6964900 100644 --- a/src/chains/views.py +++ b/src/chains/views.py @@ -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]