summaryrefslogtreecommitdiff
path: root/tests/test_utils
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
parentdf578bf175d27684c792631a2e50a05fc37c04bb (diff)
downloaddjango-311b3ad9db94c3e04f929c2622be4f10d759f45e.tar.gz
Fixed #23567 -- Made assertQuerysetEqual check Counter equality when ordered=False
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/models.py15
-rw-r--r--tests/test_utils/tests.py29
2 files changed, 43 insertions, 1 deletions
diff --git a/tests/test_utils/models.py b/tests/test_utils/models.py
index 4c6ee0d19a..b4ce172b27 100644
--- a/tests/test_utils/models.py
+++ b/tests/test_utils/models.py
@@ -1,10 +1,25 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
+class Car(models.Model):
+ name = models.CharField(max_length=100)
+
+ def __str__(self):
+ return self.name
@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=100)
+ cars = models.ManyToManyField(Car, through='PossessedCar')
def __str__(self):
return self.name
+
+@python_2_unicode_compatible
+class PossessedCar(models.Model):
+ car = models.ForeignKey(Car)
+ belongs_to = models.ForeignKey(Person)
+
+ def __str__(self):
+ return self.color
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):