Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored April 13, 2011
2  django/core/paginator.py
@@ -22,7 +22,7 @@ def validate_number(self, number):
22 22
         "Validates the given 1-based page number."
23 23
         try:
24 24
             number = int(number)
25  
-        except ValueError:
  25
+        except (TypeError, ValueError):
26 26
             raise PageNotAnInteger('That page number is not an integer')
27 27
         if number < 1:
28 28
             raise EmptyPage('That page number is less than 1')
11  tests/regressiontests/pagination_regress/tests.py
... ...
@@ -1,4 +1,4 @@
1  
-from django.core.paginator import Paginator, EmptyPage
  1
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
2 2
 from django.utils.unittest import TestCase
3 3
 
4 4
 class PaginatorTests(TestCase):
@@ -27,6 +27,15 @@ def check_attribute(self, name, paginator, expected, params):
27 27
             "For '%s', expected %s but got %s.  Paginator parameters were: %s"
28 28
             % (name, expected, got, params))
29 29
 
  30
+    def test_invalid_page_number(self):
  31
+        """
  32
+        Tests that invalid page numbers result in the correct exception being
  33
+        raised.
  34
+        """
  35
+        paginator = Paginator([1, 2, 3], 2)
  36
+        self.assertRaises(PageNotAnInteger, paginator.validate_number, None)
  37
+        self.assertRaises(PageNotAnInteger, paginator.validate_number, 'x')
  38
+
30 39
     def test_paginator(self):
31 40
         """
32 41
         Tests the paginator attributes using varying inputs.

0 notes on commit 13bb069

Please sign in to comment.
Something went wrong with that request. Please try again.