summaryrefslogtreecommitdiff
path: root/tests/pagination
diff options
context:
space:
mode:
authororf <tom@tomforb.es>2017-06-08 17:29:13 +0100
committerTim Graham <timograham@gmail.com>2017-06-13 08:13:17 -0400
commita118287bca65f2e5da110c89509941c677ebc2e1 (patch)
treeaf878dee91ba1dcf9a674185e05291c7618a0bd9 /tests/pagination
parent82175ead723f8fa3f9271fbd4b24275097029aab (diff)
Fixed #28284 -- Prevented Paginator's unordered object list warning from evaluating a QuerySet.
Diffstat (limited to 'tests/pagination')
-rw-r--r--tests/pagination/tests.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index 30fa310dc0..9319666597 100644
--- a/tests/pagination/tests.py
+++ b/tests/pagination/tests.py
@@ -328,11 +328,25 @@ class ModelPaginationTests(TestCase):
warning = warns[0]
self.assertEqual(str(warning.message), (
"Pagination may yield inconsistent results with an unordered "
- "object_list: <QuerySet [<Article: Article 1>, "
- "<Article: Article 2>, <Article: Article 3>, <Article: Article 4>, "
- "<Article: Article 5>, <Article: Article 6>, <Article: Article 7>, "
- "<Article: Article 8>, <Article: Article 9>]>"
+ "object_list: <class 'pagination.models.Article'> QuerySet."
))
# The warning points at the Paginator caller (i.e. the stacklevel
# is appropriate).
self.assertEqual(warning.filename, __file__)
+
+ def test_paginating_unordered_object_list_raises_warning(self):
+ """
+ Unordered object list warning with an object that has an orderd
+ attribute but not a model attribute.
+ """
+ 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), (
+ "Pagination may yield inconsistent results with an unordered "
+ "object_list: {!r}.".format(object_list)
+ ))