MCPcopy
hub / github.com/django/django / test_in_bulk

Method test_in_bulk

tests/prefetch_related/tests.py:1578–1591  ·  view source on GitHub ↗

In-bulk does correctly prefetch objects by not using .iterator() directly.

(self)

Source from the content-addressed store, hash-verified

1576 self.assertEqual(co_serfs, co_serfs2)
1577
1578 def test_in_bulk(self):
1579 """
1580 In-bulk does correctly prefetch objects by not using .iterator()
1581 directly.
1582 """
1583 boss1 = Employee.objects.create(name="Peter")
1584 boss2 = Employee.objects.create(name="Jack")
1585 with self.assertNumQueries(2):
1586 # Prefetch is done and it does not cause any errors.
1587 bulk = Employee.objects.prefetch_related("serfs").in_bulk(
1588 [boss1.pk, boss2.pk]
1589 )
1590 for b in bulk.values():
1591 list(b.serfs.all())
1592
1593
1594class MultiDbTests(TestCase):

Callers

nothing calls this directly

Calls 6

assertNumQueriesMethod · 0.80
in_bulkMethod · 0.80
createMethod · 0.45
prefetch_relatedMethod · 0.45
valuesMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected