forked from django-json-api/django-rest-framework-json-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_pagination.py
55 lines (48 loc) · 1.7 KB
/
test_pagination.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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