-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create a paginators file - Add ArticleLimitOffsetPagination class to paginators - set default_limit per page for Articles - Add pagination_class to Articles view class [Starts #163383191]
- Loading branch information
Showing
7 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework.pagination import LimitOffsetPagination | ||
|
||
|
||
class ArticleLimitOffsetPagination(LimitOffsetPagination): | ||
""" Class that will set article endpoint to only | ||
only 10 articles per page | ||
""" | ||
|
||
default_limit = 10 | ||
offset_query_param = "page" |
23 changes: 23 additions & 0 deletions
23
authors/apps/articles/tests/integration/test_articles_pagination.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.urls import reverse | ||
|
||
from rest_framework import status | ||
|
||
from authors.apps.articles.tests import base_class | ||
from ..test_data import test_article_data | ||
from authors.apps.articles.models import Article | ||
|
||
|
||
class TestArticleView(base_class.BaseTest): | ||
""" | ||
This Test class tests the api endpoint of get all articles | ||
""" | ||
|
||
def test_paginate_list_articles(self): | ||
""" | ||
This test method tests whether the endpoint returns paginated articles | ||
""" | ||
self.create_article_and_authenticate_test_user() | ||
response = self.client.get(self.articles_url) | ||
self.assertIn('count', response.data) | ||
self.assertIn('results', response.data) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters