Skip to content

Commit

Permalink
Set default chains pagination limit to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
fmrsabino committed Dec 22, 2021
1 parent dbb9a0d commit 9da14a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/chains/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ def test_json_payload_format(self) -> None:

class ChainPaginationViewTests(APITestCase):
def test_pagination_next_page(self) -> None:
ChainFactory.create_batch(11)
ChainFactory.create_batch(21)
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"], 11)
self.assertEqual(response.json()["count"], 21)
self.assertEqual(
response.json()["next"],
"http://testserver/api/v1/chains/?limit=10&offset=10",
"http://testserver/api/v1/chains/?limit=20&offset=20",
)
self.assertEqual(response.json()["previous"], None)
# returned items should be equal to max_limit
self.assertEqual(len(response.json()["results"]), 10)
self.assertEqual(len(response.json()["results"]), 20)

def test_request_more_than_max_limit_should_return_max_limit(self) -> None:
ChainFactory.create_batch(101)
Expand All @@ -126,18 +126,18 @@ def test_request_more_than_max_limit_should_return_max_limit(self) -> None:
self.assertEqual(len(response.json()["results"]), 100)

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

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

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["count"], 11)
self.assertEqual(response.json()["count"], 21)
self.assertEqual(response.json()["next"], None)
self.assertEqual(
response.json()["previous"],
"http://testserver/api/v1/chains/?limit=10&offset=1",
"http://testserver/api/v1/chains/?limit=20&offset=1",
)
# returned items should still be zero
self.assertEqual(len(response.json()["results"]), 0)
Expand Down
2 changes: 1 addition & 1 deletion src/chains/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ChainsListView(ListAPIView):
serializer_class = ChainSerializer
pagination_class = LimitOffsetPagination
pagination_class.max_limit = 100
pagination_class.default_limit = 10
pagination_class.default_limit = 20
queryset = Chain.objects.all()
filter_backends = [filters.OrderingFilter]
ordering_fields = ["relevance", "name"]
Expand Down

0 comments on commit 9da14a9

Please sign in to comment.