<s> from __future__ import absolute_import , unicode_literals <EOL> from django . test import TestCase <EOL> from wagtail . tests . search . models import SearchTest , SearchTestChild <EOL> from wagtail . tests . testapp . models import Advert , ManyToManyBlogPage <EOL> from wagtail . wagtailsearch import index <EOL> class TestSelectOnQuerySet ( TestCase ) : <EOL> def test_select_on_queryset_with_foreign_key ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:title>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( SearchTestChild . objects . all ( ) ) <EOL> self . assertFalse ( queryset . _prefetch_related_lookups ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . query . select_related ) <EOL> def test_select_on_queryset_with_one_to_one ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:title>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( SearchTestChild . objects . all ( ) ) <EOL> self . assertFalse ( queryset . _prefetch_related_lookups ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . query . select_related ) <EOL> def test_select_on_queryset_with_many_to_many ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:title>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( ManyToManyBlogPage . objects . all ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . _prefetch_related_lookups ) <EOL> self . assertFalse ( queryset . query . select_related ) <EOL> def test_select_on_queryset_with_reverse_foreign_key ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:name>' ) <EOL> ] ) <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( ManyToManyBlogPage . objects . all ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . _prefetch_related_lookups ) <EOL> self . assertFalse ( queryset . query . select_related ) <EOL> def test_select_on_queryset_with_reverse_one_to_one ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( SearchTest . objects . all ( ) ) <EOL> self . assertFalse ( queryset . _prefetch_related_lookups ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . query . select_related ) <EOL> def test_select_on_queryset_with_reverse_many_to_many ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:title>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( Advert . objects . all ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . _prefetch_related_lookups ) <EOL> self . assertFalse ( queryset . query . select_related ) <EOL> def test_select_on_queryset_with_taggable_manager ( self ) : <EOL> fields = index . RelatedFields ( '<STR_LIT>' , [ <EOL> index . SearchField ( '<STR_LIT:name>' ) , <EOL> ] ) <EOL> queryset = fields . select_on_queryset ( SearchTestChild . objects . all ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , queryset . _prefetch_related_lookups ) <EOL> self . assertFalse ( queryset . query . select_related ) </s>
