#NEWLINE# @ gen_test #NEWLINE# def test_multiple_error_ordered_batch( self ) : #NEWLINE# #INDENT# ( yield self . collection . remove ( ) ) #NEWLINE# ( yield self . collection . ensure_index ( 'a' , unique = True ) ) #NEWLINE# try : #NEWLINE# #INDENT# bulk = self . collection . initialize_ordered_bulk_op ( ) #NEWLINE# self . assertTrue ( isinstance ( bulk , motor . motor_tornado . MotorBulkOperationBuilder ) ) #NEWLINE# bulk . insert ( { #NEWLINE# #INDENT# 'b' : 1 , #NEWLINE# 'a' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# bulk . find ( { #NEWLINE# #INDENT# 'b' : 2 , #NEWLINE# #UNINDENT# } ) . upsert ( ) . update_one ( { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'a' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# bulk . find ( { #NEWLINE# #INDENT# 'b' : 3 , #NEWLINE# #UNINDENT# } ) . upsert ( ) . update_one ( { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'a' : 2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# bulk . find ( { #NEWLINE# #INDENT# 'b' : 2 , #NEWLINE# #UNINDENT# } ) . upsert ( ) . update_one ( { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'a' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# bulk . insert ( { #NEWLINE# #INDENT# 'b' : 4 , #NEWLINE# 'a' : 3 , #NEWLINE# #UNINDENT# } ) #NEWLINE# bulk . insert ( { #NEWLINE# #INDENT# 'b' : 5 , #NEWLINE# 'a' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# ( yield bulk . execute ( ) ) #NEWLINE# #UNINDENT# except BulkWriteError as exc : #NEWLINE# #INDENT# result = result . details #NEWLINE# self . assertEqual ( exc . code , 65 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( 'Error not raised' ) #NEWLINE# #UNINDENT# self . assertEqual ( 1 , result [ 'nInserted' ] ) #NEWLINE# self . assertEqual ( 1 , len ( result [ 'writeErrors' ] ) ) #NEWLINE# error = result [ 'writeErrors' ] [ 0 ] #NEWLINE# self . assertEqual ( 1 , error [ 'index' ] ) #NEWLINE# failed = error [ 'op' ] #NEWLINE# self . assertEqual ( 2 , failed [ 'q' ] [ 'b' ] ) #NEWLINE# self . assertEqual ( 1 , failed [ 'u' ] [ '$set' ] [ 'a' ] ) #NEWLINE# self . assertFalse ( failed [ 'multi' ] ) #NEWLINE# self . assertTrue ( failed [ 'upsert' ] ) #NEWLINE# cursor = self . collection . find ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '_id' : False , #NEWLINE# #UNINDENT# } ) #NEWLINE# docs = ( yield cursor . to_list ( None ) ) #NEWLINE# self . assertEqual ( [ { #NEWLINE# #INDENT# 'a' : 1 , #NEWLINE# 'b' : 1 , #NEWLINE# #UNINDENT# } ] , docs ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# ( yield self . collection . drop_index ( [ ( 'a' , 1 ) ] ) )