Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved pagination and settings tests to tests module #1110

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions example/tests/unit/test_pagination.py

This file was deleted.

55 changes: 55 additions & 0 deletions tests/test_pagination.py
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.