diff options
| author | Chris Beaven <smileychris@gmail.com> | 2011-04-13 11:28:42 +0000 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2011-04-13 11:28:42 +0000 |
| commit | 13bb06984cdfb937d0eac13b78c7c2337442c561 (patch) | |
| tree | 90490915cc4f79b5056cf40e16a9ed9b33497144 | |
| parent | 3b6c5e5eb21b4aad296fb750f515e66ea5c01e65 (diff) | |
Fixes Paginator.validate_number not raising a PageNotAnInteger exception when passed a non-int-castable type.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16026 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/paginator.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/pagination_regress/tests.py | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/django/core/paginator.py b/django/core/paginator.py index 9f39813704..3cec491905 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -22,7 +22,7 @@ class Paginator(object): "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') diff --git a/tests/regressiontests/pagination_regress/tests.py b/tests/regressiontests/pagination_regress/tests.py index f3bd0d1974..3feeae9083 100644 --- a/tests/regressiontests/pagination_regress/tests.py +++ b/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): @@ -27,6 +27,15 @@ class PaginatorTests(TestCase): "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. |
