#NEWLINE# def test_prefetch_subquery( self ) : #NEWLINE# #INDENT# sq = SelectQuery ( User ) . where ( ( User . username == 'foo' ) ) #NEWLINE# sq2 = SelectQuery ( Blog ) . where ( ( Blog . title == 'bar' ) ) #NEWLINE# sq3 = SelectQuery ( Comment ) . where ( ( Comment . comment == 'baz' ) ) #NEWLINE# fixed = prefetch_add_subquery ( sq , ( sq2 , sq3 ) ) #NEWLINE# fixed_sql = [ ( 'SELECT "t1"."id", "t1"."username" FROM "users" AS t1 WHERE ("t1"."username" = ?)' , [ 'foo' ] ) , ( 'SELECT "t1"."pk", "t1"."user_id", "t1"."title", "t1"."content", "t1"."pub_date" FROM "blog" AS t1 WHERE (("t1"."title" = ?) AND ("t1"."user_id" IN (SELECT "t2"."id" FROM "users" AS t2 WHERE ("t2"."username" = ?))))' , [ 'bar' , 'foo' ] ) , ( 'SELECT "t1"."id", "t1"."blog_id", "t1"."comment" FROM "comment" AS t1 WHERE (("t1"."comment" = ?) AND ("t1"."blog_id" IN (SELECT "t2"."pk" FROM "blog" AS t2 WHERE (("t2"."title" = ?) AND ("t2"."user_id" IN (SELECT "t3"."id" FROM "users" AS t3 WHERE ("t3"."username" = ?)))))))' , [ 'baz' , 'bar' , 'foo' ] ) ] #NEWLINE# for ( prefetch_result , expected ) in zip ( fixed , fixed_sql ) : #NEWLINE# #INDENT# self . assertEqual ( normal_compiler . generate_select ( prefetch_result . query ) , sq2 ) #NEWLINE# #UNINDENT# fixed = prefetch_add_subquery ( sq , ( Blog , ) ) #NEWLINE# fixed_sql = [ ( 'SELECT "t1"."id", "t1"."username" FROM "users" AS t1 WHERE ("t1"."username" = ?)' , [ 'foo' ] ) , ( 'SELECT "t1"."pk", "t1"."user_id", "t1"."title", "t1"."content", "t1"."pub_date" FROM "blog" AS t1 WHERE ("t1"."user_id" IN (SELECT "t2"."id" FROM "users" AS t2 WHERE ("t2"."username" = ?)))' , [ 'foo' ] ) ] #NEWLINE# for ( prefetch_result , expected ) in zip ( fixed , fixed_sql ) : #NEWLINE# #INDENT# self . assertEqual ( normal_compiler . generate_select ( prefetch_result . query ) , expected )