Skip to content

Commit

Permalink
Merge pull request #52 from andela/bg-add-articlescount-perpage-16594…
Browse files Browse the repository at this point in the history
…0869

#165940869 Add number of articles per page
  • Loading branch information
Oluwagbenga Joloko committed May 13, 2019
2 parents 224e0db + eae8150 commit faf0e00
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions authors/apps/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ArticlePaginator(PageNumberPagination):

def get_paginated_response(self, data):
return Response(OrderedDict([
("pageCount", len(self.page.object_list)),
('articlesCount', self.page.paginator.count),
('next', self.get_next_link()),
('previous', self.get_previous_link()),
Expand Down
4 changes: 0 additions & 4 deletions authors/apps/articles/tests/basetests.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,6 @@ def get_previous_page(self):
format='json'
)
return response
return self.client.delete(self.modify_url)
self.user
return self.client.patch(self.modify_url, data=json.dumps(self.update),
content_type="application/json")


class FilterBaseTest(TagsBaseTest):
Expand Down
19 changes: 19 additions & 0 deletions authors/apps/articles/tests/test_pagination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from authors.apps.articles.tests.basetests import PagniationBaseTest
from rest_framework import status
from authors.apps.articles.models import Article


class TestPagination(PagniationBaseTest):
Expand Down Expand Up @@ -123,3 +124,21 @@ def test_page_limit_less_than_1(self):
response.data.get("detail"),
self.error_msg
)

def test_articles_per_page_count(self):
"""
Tests return of the number of articles per page
"""
response = self.get_articles_per_page(page_limit=4)
self.assertEqual(
response.status_code,
status.HTTP_200_OK
)
self.assertEqual(
response.data.get("pageCount"),
4
)
self.assertEqual(
response.data.get("articlesCount"),
Article.objects.all().count()
)

0 comments on commit faf0e00

Please sign in to comment.