#NEWLINE# @ skipIfCustomUser #NEWLINE# def test_prefetch_categories_authors_mixin( self ) : #NEWLINE# #INDENT# author = Author . objects . create_user ( username = 'author' , email = 'author@example.com' ) #NEWLINE# category = Category . objects . create ( title = 'Category' , slug = 'category' ) #NEWLINE# for i in range ( 3 ) : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# 'title' : 'My entry' , #NEWLINE# 'content' : 'My content' , #NEWLINE# 'slug' : ( 'my-entry-%s' % entry ) , #NEWLINE# #UNINDENT# } #NEWLINE# entry = Entry . objects . create ( ** params ) #NEWLINE# entry . authors . add ( author ) #NEWLINE# entry . categories . add ( category ) #NEWLINE# #UNINDENT# class View ( object ) : #NEWLINE# #INDENT# def get_queryset( self ) : #NEWLINE# #INDENT# return Entry . objects . all ( ) #NEWLINE# #UNINDENT# #UNINDENT# class ViewCategoriesAuthorsPrefetched ( PrefetchCategoriesAuthorsMixin , View ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# with self . assertNumQueries ( 7 ) : #NEWLINE# #INDENT# for entry in View ( ) . get_queryset ( ) : #NEWLINE# #INDENT# entry . authors . count ( ) #NEWLINE# entry . categories . count ( ) #NEWLINE# #UNINDENT# #UNINDENT# with self . assertNumQueries ( 3 ) : #NEWLINE# #INDENT# for entry in ViewCategoriesAuthorsPrefetched ( ) . get_queryset ( ) : #NEWLINE# #INDENT# entry . authors . count ( ) #NEWLINE# entry . categories . count ( )