summaryrefslogtreecommitdiff
path: root/tests/pagination
diff options
context:
space:
mode:
authorMorgan Aubert <morgan.aubert@impakfinance.com>2018-04-27 17:18:15 -0400
committerTim Graham <timograham@gmail.com>2018-05-09 11:40:28 -0400
commit704443acacf0dfbcb1c52df4b260585055754ce7 (patch)
tree600147bf6114d7b490fcd253ff9797b7e7531c09 /tests/pagination
parent7ba040de7703fd06b9b35ddd31da40103d911c30 (diff)
downloaddjango-704443acacf0dfbcb1c52df4b260585055754ce7.tar.gz
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
Diffstat (limited to 'tests/pagination')
-rw-r--r--tests/pagination/tests.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index 8be81240e8..f13afc308f 100644
--- a/tests/pagination/tests.py
+++ b/tests/pagination/tests.py
@@ -1,5 +1,4 @@
import unittest
-import warnings
from datetime import datetime
from django.core.paginator import (
@@ -359,20 +358,15 @@ class ModelPaginationTests(TestCase):
self.assertIsInstance(p.object_list, list)
def test_paginating_unordered_queryset_raises_warning(self):
- with warnings.catch_warnings(record=True) as warns:
- # Prevent the RuntimeWarning subclass from appearing as an
- # exception due to the warnings.simplefilter() in runtests.py.
- warnings.filterwarnings('always', category=UnorderedObjectListWarning)
- Paginator(Article.objects.all(), 5)
- self.assertEqual(len(warns), 1)
- warning = warns[0]
- self.assertEqual(str(warning.message), (
+ msg = (
"Pagination may yield inconsistent results with an unordered "
"object_list: <class 'pagination.models.Article'> QuerySet."
- ))
+ )
+ with self.assertWarnsMessage(UnorderedObjectListWarning, msg) as cm:
+ Paginator(Article.objects.all(), 5)
# The warning points at the Paginator caller (i.e. the stacklevel
# is appropriate).
- self.assertEqual(warning.filename, __file__)
+ self.assertEqual(cm.filename, __file__)
def test_paginating_unordered_object_list_raises_warning(self):
"""
@@ -382,11 +376,9 @@ class ModelPaginationTests(TestCase):
class ObjectList:
ordered = False
object_list = ObjectList()
- with warnings.catch_warnings(record=True) as warns:
- warnings.filterwarnings('always', category=UnorderedObjectListWarning)
- Paginator(object_list, 5)
- self.assertEqual(len(warns), 1)
- self.assertEqual(str(warns[0].message), (
+ msg = (
"Pagination may yield inconsistent results with an unordered "
"object_list: {!r}.".format(object_list)
- ))
+ )
+ with self.assertWarnsMessage(UnorderedObjectListWarning, msg):
+ Paginator(object_list, 5)