-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved pagination and settings tests to tests module (#1110)
Those were already in pytest style and only needed some simplifications.
- Loading branch information
Showing
3 changed files
with
55 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
from collections import OrderedDict | ||
|
||
from rest_framework.request import Request | ||
|
||
from rest_framework_json_api.pagination import JsonApiLimitOffsetPagination | ||
|
||
|
||
class TestLimitOffsetPagination: | ||
def test_get_paginated_response(self, rf): | ||
pagination = JsonApiLimitOffsetPagination() | ||
queryset = range(1, 101) | ||
offset = 10 | ||
limit = 5 | ||
count = len(queryset) | ||
|
||
request = Request( | ||
rf.get( | ||
"/", | ||
{ | ||
pagination.limit_query_param: limit, | ||
pagination.offset_query_param: offset, | ||
}, | ||
) | ||
) | ||
queryset = list(pagination.paginate_queryset(queryset, request)) | ||
content = pagination.get_paginated_response(queryset).data | ||
|
||
expected_content = { | ||
"results": list(range(11, 16)), | ||
"links": OrderedDict( | ||
[ | ||
("first", "http://testserver/?page%5Blimit%5D=5"), | ||
( | ||
"last", | ||
"http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=100", | ||
), | ||
( | ||
"next", | ||
"http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=15", | ||
), | ||
("prev", "http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=5"), | ||
] | ||
), | ||
"meta": { | ||
"pagination": OrderedDict( | ||
[ | ||
("count", count), | ||
("limit", limit), | ||
("offset", offset), | ||
] | ||
) | ||
}, | ||
} | ||
|
||
assert content == expected_content |
File renamed without changes.