@@ -287,6 +287,8 @@ class TestLimitOffset:
287
287
def setup (self ):
288
288
class ExamplePagination (pagination .LimitOffsetPagination ):
289
289
default_limit = 10
290
+ max_limit = 15
291
+
290
292
self .pagination = ExamplePagination ()
291
293
self .queryset = range (1 , 101 )
292
294
@@ -442,7 +444,31 @@ def test_invalid_limit(self):
442
444
"""
443
445
request = Request (factory .get ('/' , {'limit' : 'invalid' , 'offset' : 0 }))
444
446
queryset = self .paginate_queryset (request )
447
+ content = self .get_paginated_content (queryset )
448
+ next_limit = self .pagination .default_limit
449
+ next_offset = self .pagination .default_limit
450
+ next_url = 'http://testserver/?limit={0}&offset={1}' .format (next_limit , next_offset )
445
451
assert queryset == [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
452
+ assert content .get ('next' ) == next_url
453
+
454
+ def test_max_limit (self ):
455
+ """
456
+ The limit defaults to the max_limit when there is a max_limit and the
457
+ requested limit is greater than the max_limit
458
+ """
459
+ offset = 50
460
+ request = Request (factory .get ('/' , {'limit' : '11235' , 'offset' : offset }))
461
+ queryset = self .paginate_queryset (request )
462
+ content = self .get_paginated_content (queryset )
463
+ max_limit = self .pagination .max_limit
464
+ next_offset = offset + max_limit
465
+ prev_offset = offset - max_limit
466
+ base_url = 'http://testserver/?limit={0}' .format (max_limit )
467
+ next_url = base_url + '&offset={0}' .format (next_offset )
468
+ prev_url = base_url + '&offset={0}' .format (prev_offset )
469
+ assert queryset == list (range (51 , 66 ))
470
+ assert content .get ('next' ) == next_url
471
+ assert content .get ('previous' ) == prev_url
446
472
447
473
448
474
class TestCursorPagination :
0 commit comments