mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #29244 -- Prevented Paginator.count() from silencing TypeError and AttributeError.
This commit is contained in:
parent
f1bf069ec1
commit
3767c7ff39
2 changed files with 24 additions and 10 deletions
|
@ -1,4 +1,3 @@
|
|||
import unittest
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
|
||||
|
@ -6,13 +5,13 @@ from django.core.paginator import (
|
|||
EmptyPage, InvalidPage, PageNotAnInteger, Paginator,
|
||||
UnorderedObjectListWarning,
|
||||
)
|
||||
from django.test import TestCase
|
||||
from django.test import SimpleTestCase, TestCase
|
||||
|
||||
from .custom import ValidAdjacentNumsPaginator
|
||||
from .models import Article
|
||||
|
||||
|
||||
class PaginationTests(unittest.TestCase):
|
||||
class PaginationTests(SimpleTestCase):
|
||||
"""
|
||||
Tests for the Paginator and Page classes.
|
||||
"""
|
||||
|
@ -151,6 +150,22 @@ class PaginationTests(unittest.TestCase):
|
|||
self.assertEqual(5, paginator.num_pages)
|
||||
self.assertEqual([1, 2, 3, 4, 5], list(paginator.page_range))
|
||||
|
||||
def test_count_does_not_silence_attribute_error(self):
|
||||
class AttributeErrorContainer:
|
||||
def count(self):
|
||||
raise AttributeError('abc')
|
||||
|
||||
with self.assertRaisesMessage(AttributeError, 'abc'):
|
||||
Paginator(AttributeErrorContainer(), 10).count()
|
||||
|
||||
def test_count_does_not_silence_type_error(self):
|
||||
class TypeErrorContainer:
|
||||
def count(self):
|
||||
raise TypeError('abc')
|
||||
|
||||
with self.assertRaisesMessage(TypeError, 'abc'):
|
||||
Paginator(TypeErrorContainer(), 10).count()
|
||||
|
||||
def check_indexes(self, params, page_num, indexes):
|
||||
"""
|
||||
Helper method that instantiates a Paginator object from the passed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue