#NEWLINE# def test_forwarders( self ) : #NEWLINE# #INDENT# author = Author . objects . create ( name = 'Johnny' ) #NEWLINE# tags = [ ] #NEWLINE# for i in range ( 100 ) : #NEWLINE# #INDENT# tags . append ( Tag . objects . create ( name = ( 'Tag %s' % i ) ) ) #NEWLINE# #UNINDENT# for i in range ( 10 , 20 ) : #NEWLINE# #INDENT# book = Book . objects . create ( name = ( 'Book %s' % i ) , author = author ) #NEWLINE# if ( VERSION < ( 1 , 2 ) ) : #NEWLINE# #INDENT# from . models import Book_Tag #NEWLINE# for tag in tags [ : : 7 ] : #NEWLINE# #INDENT# Book_Tag . objects . create ( tag = tag , book = book ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# book . tags . add ( * tags [ : : 7 ] ) #NEWLINE# #UNINDENT# for j in range ( 3 ) : #NEWLINE# #INDENT# BookNote . objects . create ( notes = ( 'Note %s/%s' % ( i , tag ) ) , book = book , bogus = book ) #NEWLINE# #UNINDENT# #UNINDENT# with self . assertNumQueries ( 2 ) : #NEWLINE# #INDENT# for note in BookNote . objects . select_related ( 'book' , 'bogus' ) . prefetch ( 'book__tags' ) : #NEWLINE# #INDENT# self . assertTrue ( hasattr ( note . book , 'prefetched_tags' ) ) #NEWLINE# self . assertEqual ( len ( note . book . selected_tags ) , 15 , i ) #NEWLINE# self . assertEqual ( set ( note . book . selected_tags ) , set ( tags [ : : 7 ] ) , i ) #NEWLINE# self . assertTrue ( isinstance ( note . bogus , Book ) ) #NEWLINE# #UNINDENT# #UNINDENT# for note in BookNote . objects . select_related ( 'book' ) : #NEWLINE# #INDENT# self . assertFalse ( hasattr ( note . book , 'prefetched_tags' ) ) #NEWLINE# self . assertEqual ( len ( note . book . selected_tags ) , 15 , i ) #NEWLINE# self . assertEqual ( set ( note . book . selected_tags ) , set ( tags [ : : 7 ] ) , i )