#NEWLINE# def test_bulk_write( self ) : #NEWLINE# #INDENT# coll = expected . client . pymongo_test . test #NEWLINE# coll . drop ( ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# coll . bulk_write ( [ InsertOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , UpdateOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , DeleteOne ( { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] #NEWLINE# succeeded = results [ 'succeeded' ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# operation_id = started [ 0 ] . operation_id #NEWLINE# pairs = list ( zip ( started , succeeded ) ) #NEWLINE# self . assertEqual ( 3 , len ( pairs ) ) #NEWLINE# for ( start , succeed ) in pairs : #NEWLINE# #INDENT# self . assertIsInstance ( start , monitoring . CommandStartedEvent ) #NEWLINE# self . assertEqual ( 'pymongo_test' , start . database_name ) #NEWLINE# self . assertIsInstance ( start . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , start . connection_id ) #NEWLINE# self . assertIsInstance ( succeed , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeed . duration_micros , int ) #NEWLINE# self . assertEqual ( start . command_name , succeed . command_name ) #NEWLINE# self . assertEqual ( start . request_id , succeed . request_id ) #NEWLINE# self . assertEqual ( start . connection_id , succeed . connection_id ) #NEWLINE# self . assertEqual ( start . operation_id , operation_id ) #NEWLINE# self . assertEqual ( succeed . operation_id , operation_id ) #NEWLINE# #UNINDENT# expected = SON ( [ ( 'insert' , coll . name ) , ( 'ordered' , True ) , ( 'documents' , [ { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ] ) ] ) #NEWLINE# self . assertEqual ( expected , started [ 0 ] . command ) #NEWLINE# expected = SON ( [ ( 'update' , coll . name ) , ( 'ordered' , True ) , ( 'updates' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , ( 'u' , { #NEWLINE# #INDENT# '$set' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , ( 'multi' , False ) , ( 'upsert' , False ) ] ) ] ) ] ) #NEWLINE# self . assertEqual ( expected , started [ 1 ] . command ) #NEWLINE# expected = SON ( [ ( 'delete' , coll . name ) , ( 'ordered' , True ) , ( 'deletes' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# '_id' : 1 , #NEWLINE# #UNINDENT# } ) , ( 'limit' , 1 ) ] ) ] ) ] ) #NEWLINE# self . assertEqual ( expected , started [ 2 ] . command )