MCPcopy
hub / github.com/django/django / test_generic_rel

Method test_generic_rel

tests/prefetch_related/tests.py:788–814  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

786 self.assertEqual(lst1, lst2)
787
788 def test_generic_rel(self):
789 bookmark = Bookmark.objects.create(url="http://www.djangoproject.com/")
790 TaggedItem.objects.create(content_object=bookmark, tag="django")
791 TaggedItem.objects.create(
792 content_object=bookmark, favorite=bookmark, tag="python"
793 )
794
795 # Control lookups.
796 with self.assertNumQueries(4):
797 lst1 = self.traverse_qs(
798 Bookmark.objects.prefetch_related(
799 "tags", "tags__content_object", "favorite_tags"
800 ),
801 [["tags", "content_object"], ["favorite_tags"]],
802 )
803
804 # Test lookups.
805 with self.assertNumQueries(4):
806 lst2 = self.traverse_qs(
807 Bookmark.objects.prefetch_related(
808 Prefetch("tags", to_attr="tags_lst"),
809 Prefetch("tags_lst__content_object"),
810 Prefetch("favorite_tags"),
811 ),
812 [["tags_lst", "content_object"], ["favorite_tags"]],
813 )
814 self.assertEqual(lst1, lst2)
815
816 def test_traverse_single_item_property(self):
817 # Control lookups.

Callers

nothing calls this directly

Calls 5

traverse_qsMethod · 0.95
PrefetchClass · 0.90
assertNumQueriesMethod · 0.80
createMethod · 0.45
prefetch_relatedMethod · 0.45

Tested by

no test coverage detected