Skip to content

Commit

Permalink
Fixes Paginator.validate_number not raising a PageNotAnInteger except…
Browse files Browse the repository at this point in the history
…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
SmileyChris committed Apr 13, 2011
1 parent 3b6c5e5 commit 13bb069
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/core/paginator.py
Expand Up @@ -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')
Expand Down
11 changes: 10 additions & 1 deletion tests/regressiontests/pagination_regress/tests.py
@@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 13bb069

Please sign in to comment.