-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #548 from adfinis/pagination-settings
feat(api): make pagination configurable
- Loading branch information
Showing
4 changed files
with
50 additions
and
2 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
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,7 @@ | ||
from django.conf import settings | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
|
||
class APIPagination(PageNumberPagination): | ||
page_size_query_param = "page_size" | ||
max_page_size = settings.PAGINATION_MAX_PAGE_SIZE |
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,26 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"query_params,expected", | ||
[ | ||
({"page_size": 10}, 10), | ||
({"page_size": 120}, 110), # max page size reached | ||
({}, 100), # default page size | ||
], | ||
) | ||
def test_pagination(db, client, template_factory, query_params, expected, mocker): | ||
mocker.patch( | ||
"document_merge_service.api.pagination.APIPagination.max_page_size", 110 | ||
) | ||
|
||
template_factory.create_batch(120) | ||
|
||
response = client.get(reverse("template-list"), data=query_params) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
result = response.json() | ||
assert result["count"] == 120 | ||
assert len(result["results"]) == expected |
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