Skip to content

Commit

Permalink
Moved pagination and settings tests to tests module (#1110)
Browse files Browse the repository at this point in the history
Those were already in pytest style and only needed some simplifications.
  • Loading branch information
sliverc authored Nov 30, 2022
1 parent adfffee commit ee7b7de
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 92 deletions.
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.

0 comments on commit ee7b7de

Please sign in to comment.