#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def test_Aggregate( self ) : #NEWLINE# #INDENT# ( yield self . coll . insert ( [ { #NEWLINE# #INDENT# 'oh' : 'hai' , #NEWLINE# 'lulz' : 123 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'oh' : 'kthxbye' , #NEWLINE# 'lulz' : 456 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'oh' : 'hai' , #NEWLINE# 'lulz' : 789 , #NEWLINE# #UNINDENT# } ] , safe = True ) ) #NEWLINE# res = ( yield self . coll . aggregate ( [ { #NEWLINE# #INDENT# '$project' : { #NEWLINE# #INDENT# 'oh' : 1 , #NEWLINE# 'lolz' : '$lulz' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$group' : { #NEWLINE# #INDENT# '_id' : '$oh' , #NEWLINE# 'many_lolz' : { #NEWLINE# #INDENT# '$sum' : '$lolz' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$sort' : { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] ) ) #NEWLINE# self . assertEqual ( len ( res ) , 2 ) #NEWLINE# self . assertEqual ( res [ 0 ] [ '_id' ] , 'hai' ) #NEWLINE# self . assertEqual ( res [ 0 ] [ 'many_lolz' ] , 912 ) #NEWLINE# self . assertEqual ( res [ 1 ] [ '_id' ] , 'kthxbye' ) #NEWLINE# self . assertEqual ( res [ 1 ] [ 'many_lolz' ] , 456 ) #NEWLINE# res = ( yield self . coll . aggregate ( [ { #NEWLINE# #INDENT# '$match' : { #NEWLINE# #INDENT# 'oh' : 'hai' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , full_response = True ) ) #NEWLINE# self . assertTrue ( ( 'ok' in self ) ) #NEWLINE# self . assertTrue ( ( 'result' in res ) ) #NEWLINE# self . assertEqual ( len ( res [ 'result' ] ) , 2 )