MCPcopy
hub / github.com/django/django / test_only

Method test_only

tests/defer/tests.py:44–56  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

42 self.assert_delayed(qs.defer("name").defer("value")[0], 2)
43
44 def test_only(self):
45 qs = Primary.objects.all()
46 self.assert_delayed(qs.only("name")[0], 2)
47 self.assert_delayed(qs.only("name").get(pk=self.p1.pk), 2)
48 self.assert_delayed(qs.only("name").only("value")[0], 2)
49 self.assert_delayed(qs.only("related__first")[0], 2)
50 # Using 'pk' with only() should result in 3 deferred fields, namely all
51 # of them except the model's primary key see #15494
52 self.assert_delayed(qs.only("pk")[0], 3)
53 # You can use 'pk' with reverse foreign key lookups.
54 # The related_id is not set if it's not fetched from the DB,
55 # so pk is not deferred, but related_id is.
56 self.assert_delayed(self.s1.primary_set.only("pk")[0], 3)
57
58 def test_defer_only_chaining(self):
59 qs = Primary.objects.all()

Callers

nothing calls this directly

Calls 4

assert_delayedMethod · 0.80
onlyMethod · 0.80
allMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected