summaryrefslogtreecommitdiff
path: root/tests/test_utils/tests.py
diff options
context:
space:
mode:
authorThomas Chaumeny <thomas.chaumeny@polyconseil.fr>2014-09-29 17:17:44 +0200
committerSimon Charette <charette.s@gmail.com>2014-09-29 12:00:14 -0400
commit311b3ad9db94c3e04f929c2622be4f10d759f45e (patch)
tree2c4826cc9a8b2de571271e4171162827d852413e /tests/test_utils/tests.py
parentdf578bf175d27684c792631a2e50a05fc37c04bb (diff)
Fixed #23567 -- Made assertQuerysetEqual check Counter equality when ordered=False
Diffstat (limited to 'tests/test_utils/tests.py')
-rw-r--r--tests/test_utils/tests.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 8cd0019f7b..ef3114cd16 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -14,7 +14,7 @@ from django.test.html import HTMLParseError, parse_html
from django.test.utils import CaptureQueriesContext, override_settings
from django.utils import six
-from .models import Person
+from .models import Car, Person, PossessedCar
from .views import empty_response
@@ -178,6 +178,33 @@ class AssertQuerysetEqualTests(TestCase):
[repr(self.p1)]
)
+ def test_repeated_values(self):
+ """
+ Test that assertQuerysetEqual checks the number of appearance of each item
+ when used with option ordered=False.
+ """
+ batmobile = Car.objects.create(name='Batmobile')
+ k2000 = Car.objects.create(name='K 2000')
+ PossessedCar.objects.bulk_create([
+ PossessedCar(car=batmobile, belongs_to=self.p1),
+ PossessedCar(car=batmobile, belongs_to=self.p1),
+ PossessedCar(car=k2000, belongs_to=self.p1),
+ PossessedCar(car=k2000, belongs_to=self.p1),
+ PossessedCar(car=k2000, belongs_to=self.p1),
+ PossessedCar(car=k2000, belongs_to=self.p1),
+ ])
+ with self.assertRaises(AssertionError):
+ self.assertQuerysetEqual(
+ self.p1.cars.all(),
+ [repr(batmobile), repr(k2000)],
+ ordered=False
+ )
+ self.assertQuerysetEqual(
+ self.p1.cars.all(),
+ [repr(batmobile)] * 2 + [repr(k2000)] * 4,
+ ordered=False
+ )
+
@override_settings(ROOT_URLCONF='test_utils.urls')
class CaptureQueriesContextManagerTests(TestCase):