Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes Paginator.validate_number not raising a PageNotAnInteger except…

…ion when passed a non-int-castable type.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16026 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 13bb06984cdfb937d0eac13b78c7c2337442c561 1 parent 3b6c5e5
Chris Beaven SmileyChris authored
2  django/core/paginator.py
View
@@ -22,7 +22,7 @@ def validate_number(self, number):
"Validates the given 1-based page number."
try:
number = int(number)
- except ValueError:
+ except (TypeError, ValueError):
raise PageNotAnInteger('That page number is not an integer')
if number < 1:
raise EmptyPage('That page number is less than 1')
11 tests/regressiontests/pagination_regress/tests.py
View
@@ -1,4 +1,4 @@
-from django.core.paginator import Paginator, EmptyPage
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils.unittest import TestCase
class PaginatorTests(TestCase):
@@ -27,6 +27,15 @@ def check_attribute(self, name, paginator, expected, params):
"For '%s', expected %s but got %s. Paginator parameters were: %s"
% (name, expected, got, params))
+ def test_invalid_page_number(self):
+ """
+ Tests that invalid page numbers result in the correct exception being
+ raised.
+ """
+ paginator = Paginator([1, 2, 3], 2)
+ self.assertRaises(PageNotAnInteger, paginator.validate_number, None)
+ self.assertRaises(PageNotAnInteger, paginator.validate_number, 'x')
+
def test_paginator(self):
"""
Tests the paginator attributes using varying inputs.
Please sign in to comment.
Something went wrong with that request. Please try again.