File tree Expand file tree Collapse file tree 3 files changed +55
-92
lines changed Expand file tree Collapse file tree 3 files changed +55
-92
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments