@@ -633,6 +633,164 @@ def test_cursor_pagination(self):
633
633
634
634
assert isinstance (self .pagination .to_html (), type ('' ))
635
635
636
+ def test_cursor_pagination_with_page_size (self ):
637
+ (previous , current , next , previous_url , next_url ) = self .get_pages ('/?page_size=20' )
638
+
639
+ assert previous is None
640
+ assert current == [1 , 1 , 1 , 1 , 1 , 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ]
641
+ assert next == [7 , 7 , 7 , 8 , 9 , 9 , 9 , 9 , 9 , 9 ]
642
+
643
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
644
+ assert previous == [1 , 1 , 1 , 1 , 1 , 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ]
645
+ assert current == [7 , 7 , 7 , 8 , 9 , 9 , 9 , 9 , 9 , 9 ]
646
+ assert next is None
647
+
648
+ def test_cursor_pagination_with_page_size_over_limit (self ):
649
+ (previous , current , next , previous_url , next_url ) = self .get_pages ('/?page_size=30' )
650
+
651
+ assert previous is None
652
+ assert current == [1 , 1 , 1 , 1 , 1 , 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ]
653
+ assert next == [7 , 7 , 7 , 8 , 9 , 9 , 9 , 9 , 9 , 9 ]
654
+
655
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
656
+ assert previous == [1 , 1 , 1 , 1 , 1 , 1 , 2 , 3 , 4 , 4 , 4 , 4 , 5 , 6 , 7 , 7 , 7 , 7 , 7 , 7 ]
657
+ assert current == [7 , 7 , 7 , 8 , 9 , 9 , 9 , 9 , 9 , 9 ]
658
+ assert next is None
659
+
660
+ def test_cursor_pagination_with_page_size_zero (self ):
661
+ (previous , current , next , previous_url , next_url ) = self .get_pages ('/?page_size=0' )
662
+
663
+ assert previous is None
664
+ assert current == [1 , 1 , 1 , 1 , 1 ]
665
+ assert next == [1 , 2 , 3 , 4 , 4 ]
666
+
667
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
668
+
669
+ assert previous == [1 , 1 , 1 , 1 , 1 ]
670
+ assert current == [1 , 2 , 3 , 4 , 4 ]
671
+ assert next == [4 , 4 , 5 , 6 , 7 ]
672
+
673
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
674
+
675
+ assert previous == [1 , 2 , 3 , 4 , 4 ]
676
+ assert current == [4 , 4 , 5 , 6 , 7 ]
677
+ assert next == [7 , 7 , 7 , 7 , 7 ]
678
+
679
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
680
+
681
+ assert previous == [4 , 4 , 4 , 5 , 6 ] # Paging artifact
682
+ assert current == [7 , 7 , 7 , 7 , 7 ]
683
+ assert next == [7 , 7 , 7 , 8 , 9 ]
684
+
685
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
686
+
687
+ assert previous == [7 , 7 , 7 , 7 , 7 ]
688
+ assert current == [7 , 7 , 7 , 8 , 9 ]
689
+ assert next == [9 , 9 , 9 , 9 , 9 ]
690
+
691
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
692
+
693
+ assert previous == [7 , 7 , 7 , 8 , 9 ]
694
+ assert current == [9 , 9 , 9 , 9 , 9 ]
695
+ assert next is None
696
+
697
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
698
+
699
+ assert previous == [7 , 7 , 7 , 7 , 7 ]
700
+ assert current == [7 , 7 , 7 , 8 , 9 ]
701
+ assert next == [9 , 9 , 9 , 9 , 9 ]
702
+
703
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
704
+
705
+ assert previous == [4 , 4 , 5 , 6 , 7 ]
706
+ assert current == [7 , 7 , 7 , 7 , 7 ]
707
+ assert next == [8 , 9 , 9 , 9 , 9 ] # Paging artifact
708
+
709
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
710
+
711
+ assert previous == [1 , 2 , 3 , 4 , 4 ]
712
+ assert current == [4 , 4 , 5 , 6 , 7 ]
713
+ assert next == [7 , 7 , 7 , 7 , 7 ]
714
+
715
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
716
+
717
+ assert previous == [1 , 1 , 1 , 1 , 1 ]
718
+ assert current == [1 , 2 , 3 , 4 , 4 ]
719
+ assert next == [4 , 4 , 5 , 6 , 7 ]
720
+
721
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
722
+
723
+ assert previous is None
724
+ assert current == [1 , 1 , 1 , 1 , 1 ]
725
+ assert next == [1 , 2 , 3 , 4 , 4 ]
726
+
727
+ def test_cursor_pagination_with_page_size_negative (self ):
728
+ (previous , current , next , previous_url , next_url ) = self .get_pages ('/?page_size=-5' )
729
+
730
+ assert previous is None
731
+ assert current == [1 , 1 , 1 , 1 , 1 ]
732
+ assert next == [1 , 2 , 3 , 4 , 4 ]
733
+
734
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
735
+
736
+ assert previous == [1 , 1 , 1 , 1 , 1 ]
737
+ assert current == [1 , 2 , 3 , 4 , 4 ]
738
+ assert next == [4 , 4 , 5 , 6 , 7 ]
739
+
740
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
741
+
742
+ assert previous == [1 , 2 , 3 , 4 , 4 ]
743
+ assert current == [4 , 4 , 5 , 6 , 7 ]
744
+ assert next == [7 , 7 , 7 , 7 , 7 ]
745
+
746
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
747
+
748
+ assert previous == [4 , 4 , 4 , 5 , 6 ] # Paging artifact
749
+ assert current == [7 , 7 , 7 , 7 , 7 ]
750
+ assert next == [7 , 7 , 7 , 8 , 9 ]
751
+
752
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
753
+
754
+ assert previous == [7 , 7 , 7 , 7 , 7 ]
755
+ assert current == [7 , 7 , 7 , 8 , 9 ]
756
+ assert next == [9 , 9 , 9 , 9 , 9 ]
757
+
758
+ (previous , current , next , previous_url , next_url ) = self .get_pages (next_url )
759
+
760
+ assert previous == [7 , 7 , 7 , 8 , 9 ]
761
+ assert current == [9 , 9 , 9 , 9 , 9 ]
762
+ assert next is None
763
+
764
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
765
+
766
+ assert previous == [7 , 7 , 7 , 7 , 7 ]
767
+ assert current == [7 , 7 , 7 , 8 , 9 ]
768
+ assert next == [9 , 9 , 9 , 9 , 9 ]
769
+
770
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
771
+
772
+ assert previous == [4 , 4 , 5 , 6 , 7 ]
773
+ assert current == [7 , 7 , 7 , 7 , 7 ]
774
+ assert next == [8 , 9 , 9 , 9 , 9 ] # Paging artifact
775
+
776
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
777
+
778
+ assert previous == [1 , 2 , 3 , 4 , 4 ]
779
+ assert current == [4 , 4 , 5 , 6 , 7 ]
780
+ assert next == [7 , 7 , 7 , 7 , 7 ]
781
+
782
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
783
+
784
+ assert previous == [1 , 1 , 1 , 1 , 1 ]
785
+ assert current == [1 , 2 , 3 , 4 , 4 ]
786
+ assert next == [4 , 4 , 5 , 6 , 7 ]
787
+
788
+ (previous , current , next , previous_url , next_url ) = self .get_pages (previous_url )
789
+
790
+ assert previous is None
791
+ assert current == [1 , 1 , 1 , 1 , 1 ]
792
+ assert next == [1 , 2 , 3 , 4 , 4 ]
793
+
636
794
637
795
class TestCursorPagination (CursorPaginationTestsMixin ):
638
796
"""
@@ -671,6 +829,8 @@ def __getitem__(self, sliced):
671
829
672
830
class ExamplePagination (pagination .CursorPagination ):
673
831
page_size = 5
832
+ page_size_query_param = 'page_size'
833
+ max_page_size = 20
674
834
ordering = 'created'
675
835
676
836
self .pagination = ExamplePagination ()
@@ -727,6 +887,8 @@ class TestCursorPaginationWithValueQueryset(CursorPaginationTestsMixin, TestCase
727
887
def setUp (self ):
728
888
class ExamplePagination (pagination .CursorPagination ):
729
889
page_size = 5
890
+ page_size_query_param = 'page_size'
891
+ max_page_size = 20
730
892
ordering = 'created'
731
893
732
894
self .pagination = ExamplePagination ()
0 commit comments