summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-12-13 13:33:11 +0200
committerAnssi Kääriäinen <akaariai@gmail.com>2012-12-13 13:33:11 +0200
commit088d3bc2f84b6b68fee7e5de053b58049bd110e7 (patch)
treeecb350eeba16a0b05c131008a552a91f23644e95 /django
parent6ed6a18a033ba78de9418f5b56b80f8b3d3aaf11 (diff)
Fixed #19462 -- Made assertQuerysetEqual detect undefined ordering
If there are more than one values to compare against and the qs isn't ordered then assertQuerysetEqual will raise a ValueError.
Diffstat (limited to 'django')
-rw-r--r--django/test/testcases.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index f673a10d08..3af6b8c346 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -767,6 +767,12 @@ class TransactionTestCase(SimpleTestCase):
items = six.moves.map(transform, qs)
if not ordered:
return self.assertEqual(set(items), set(values))
+ values = list(values)
+ # For example qs.iterator() could be passed as qs, but it does not
+ # have 'ordered' attribute.
+ if len(values) > 1 and hasattr(qs, 'ordered') and not qs.ordered:
+ raise ValueError("Trying to compare non-ordered queryset "
+ "against more than one ordered values")
return self.assertEqual(list(items), values)
def assertNumQueries(self, num, func=None, *args, **kwargs):