MCPcopy
hub / github.com/django/django / test_repeated_values

Method test_repeated_values

tests/test_utils/tests.py:333–356  ·  view source on GitHub ↗

assertQuerySetEqual checks the number of appearance of each item when used with option ordered=False.

(self)

Source from the content-addressed store, hash-verified

331 self.assertQuerySetEqual(Person.objects.filter(name="p1"), [self.p1])
332
333 def test_repeated_values(self):
334 """
335 assertQuerySetEqual checks the number of appearance of each item
336 when used with option ordered=False.
337 """
338 batmobile = Car.objects.create(name="Batmobile")
339 k2000 = Car.objects.create(name="K 2000")
340 PossessedCar.objects.bulk_create(
341 [
342 PossessedCar(car=batmobile, belongs_to=self.p1),
343 PossessedCar(car=batmobile, belongs_to=self.p1),
344 PossessedCar(car=k2000, belongs_to=self.p1),
345 PossessedCar(car=k2000, belongs_to=self.p1),
346 PossessedCar(car=k2000, belongs_to=self.p1),
347 PossessedCar(car=k2000, belongs_to=self.p1),
348 ]
349 )
350 with self.assertRaises(AssertionError):
351 self.assertQuerySetEqual(
352 self.p1.cars.all(), [batmobile, k2000], ordered=False
353 )
354 self.assertQuerySetEqual(
355 self.p1.cars.all(), [batmobile] * 2 + [k2000] * 4, ordered=False
356 )
357
358 def test_maxdiff(self):
359 names = ["Joe Smith %s" % i for i in range(20)]

Callers

nothing calls this directly

Calls 5

PossessedCarClass · 0.85
bulk_createMethod · 0.80
assertQuerySetEqualMethod · 0.80
createMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected