@@ -37,6 +37,38 @@ def test_queryset_paginator_invalid(app, todo):
3737 Pagination (iterable = Todo .objects , page = - 1 , per_page = 10 , first_page_index = 0 )
3838
3939
40+ def test_per_page_validation (app , todo ):
41+ """Test that per_page validation works for all pagination classes"""
42+ Todo = todo
43+
44+ # Test Pagination with per_page=0
45+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
46+ Pagination (iterable = Todo .objects , page = 1 , per_page = 0 )
47+
48+ # Test Pagination with negative per_page
49+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
50+ Pagination (iterable = Todo .objects , page = 1 , per_page = - 5 )
51+
52+ # Test KeysetPagination with per_page=0
53+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
54+ KeysetPagination (Todo .objects , per_page = 0 )
55+
56+ # Test KeysetPagination with negative per_page
57+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
58+ KeysetPagination (Todo .objects , per_page = - 5 )
59+
60+ # Test ListFieldPagination with per_page=0
61+ comments = [f"comment: { i } " for i in range (10 )]
62+ test_todo = Todo (title = "test" , comments = comments ).save ()
63+
64+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
65+ ListFieldPagination (Todo .objects , test_todo .id , "comments" , 1 , per_page = 0 )
66+
67+ # Test ListFieldPagination with negative per_page
68+ with pytest .raises (ValueError , match = "per_page must be a positive integer" ):
69+ ListFieldPagination (Todo .objects , test_todo .id , "comments" , 1 , per_page = - 5 )
70+
71+
4072def test_queryset_paginator (app , todo ):
4173 Todo = todo
4274 paginator = Pagination (Todo .objects , 1 , 10 )
0 commit comments