Skip to content

Commit ee7b7de

Browse files
authored
Moved pagination and settings tests to tests module (#1110)
Those were already in pytest style and only needed some simplifications.
1 parent adfffee commit ee7b7de

File tree

3 files changed

+55
-92
lines changed

3 files changed

+55
-92
lines changed

Diff for: example/tests/unit/test_pagination.py

-92
This file was deleted.

Diff for: tests/test_pagination.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from collections import OrderedDict
2+
3+
from rest_framework.request import Request
4+
5+
from rest_framework_json_api.pagination import JsonApiLimitOffsetPagination
6+
7+
8+
class TestLimitOffsetPagination:
9+
def test_get_paginated_response(self, rf):
10+
pagination = JsonApiLimitOffsetPagination()
11+
queryset = range(1, 101)
12+
offset = 10
13+
limit = 5
14+
count = len(queryset)
15+
16+
request = Request(
17+
rf.get(
18+
"/",
19+
{
20+
pagination.limit_query_param: limit,
21+
pagination.offset_query_param: offset,
22+
},
23+
)
24+
)
25+
queryset = list(pagination.paginate_queryset(queryset, request))
26+
content = pagination.get_paginated_response(queryset).data
27+
28+
expected_content = {
29+
"results": list(range(11, 16)),
30+
"links": OrderedDict(
31+
[
32+
("first", "http://testserver/?page%5Blimit%5D=5"),
33+
(
34+
"last",
35+
"http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=100",
36+
),
37+
(
38+
"next",
39+
"http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=15",
40+
),
41+
("prev", "http://testserver/?page%5Blimit%5D=5&page%5Boffset%5D=5"),
42+
]
43+
),
44+
"meta": {
45+
"pagination": OrderedDict(
46+
[
47+
("count", count),
48+
("limit", limit),
49+
("offset", offset),
50+
]
51+
)
52+
},
53+
}
54+
55+
assert content == expected_content
File renamed without changes.

0 commit comments

Comments
 (0)