#NEWLINE# def test_legacy_writes( self ) : #NEWLINE# #INDENT# with warnings . catch_warnings ( ) : #NEWLINE# #INDENT# warnings . simplefilter ( 'ignore' , DeprecationWarning ) #NEWLINE# coll = self . client . pymongo_test . test #NEWLINE# coll . drop ( ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# _id = coll . insert ( { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'insert' , coll . name ) , ( 'ordered' , True ) , ( 'documents' , [ { #NEWLINE# #INDENT# '_id' : _id , #NEWLINE# 'x' : 1 , #NEWLINE# #UNINDENT# } ] ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'insert' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# _id = coll . insert ( { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , w = 0 ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'insert' , coll . name ) , ( 'ordered' , True ) , ( 'documents' , [ { #NEWLINE# #INDENT# '_id' : _id , #NEWLINE# 'x' : 1 , #NEWLINE# #UNINDENT# } ] ) , ( 'writeConcern' , { #NEWLINE# #INDENT# 'w' : 0 , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'insert' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# self . assertEqual ( succeeded . reply , { #NEWLINE# #INDENT# 'ok' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# _id = coll . insert ( { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , w = 1 ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'insert' , coll . name ) , ( 'ordered' , True ) , ( 'documents' , [ { #NEWLINE# #INDENT# '_id' : _id , #NEWLINE# 'x' : 1 , #NEWLINE# #UNINDENT# } ] ) , ( 'writeConcern' , { #NEWLINE# #INDENT# 'w' : 1 , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'insert' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# res = coll . remove ( { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , w = 1 ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'delete' , coll . name ) , ( 'ordered' , True ) , ( 'deletes' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } ) , ( 'limit' , 0 ) ] ) ] ) , ( 'writeConcern' , { #NEWLINE# #INDENT# 'w' : 1 , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'delete' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( res [ 'n' ] , reply . get ( 'n' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# oid = ObjectId ( ) #NEWLINE# coll . update ( { #NEWLINE# #INDENT# '_id' : oid , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '_id' : oid , #NEWLINE# 'x' : 1 , #NEWLINE# #UNINDENT# } , upsert = True , w = 1 ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'update' , coll . name ) , ( 'ordered' , True ) , ( 'updates' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# '_id' : oid , #NEWLINE# #UNINDENT# } ) , ( 'u' , { #NEWLINE# #INDENT# '_id' : oid , #NEWLINE# 'x' : 1 , #NEWLINE# #UNINDENT# } ) , ( 'multi' , False ) , ( 'upsert' , True ) ] ) ] ) , ( 'writeConcern' , { #NEWLINE# #INDENT# 'w' : 1 , #NEWLINE# #UNINDENT# } ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'update' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . assertEqual ( [ { #NEWLINE# #INDENT# 'index' : 0 , #NEWLINE# '_id' : oid , #NEWLINE# #UNINDENT# } ] , reply . get ( 'upserted' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# coll . update ( { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'update' , coll . name ) , ( 'ordered' , True ) , ( 'updates' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } ) , ( 'u' , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , ( 'multi' , False ) , ( 'upsert' , False ) ] ) ] ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'update' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# coll . update ( { #NEWLINE# #INDENT# 'x' : 2 , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , multi = True ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'update' , coll . name ) , ( 'ordered' , True ) , ( 'updates' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# 'x' : 2 , #NEWLINE# #UNINDENT# } ) , ( 'u' , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'x' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) , ( 'multi' , True ) , ( 'upsert' , False ) ] ) ] ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'update' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . listener . results . clear ( ) #NEWLINE# coll . remove ( { #NEWLINE# #INDENT# 'x' : 3 , #NEWLINE# #UNINDENT# } , multi = False ) #NEWLINE# results = self . listener . results #NEWLINE# started = results [ 'started' ] [ 0 ] #NEWLINE# succeeded = results [ 'succeeded' ] [ 0 ] #NEWLINE# self . assertEqual ( 0 , len ( results [ 'failed' ] ) ) #NEWLINE# self . assertIsInstance ( started , monitoring . CommandStartedEvent ) #NEWLINE# expected = SON ( [ ( 'delete' , coll . name ) , ( 'ordered' , True ) , ( 'deletes' , [ SON ( [ ( 'q' , { #NEWLINE# #INDENT# 'x' : 3 , #NEWLINE# #UNINDENT# } ) , ( 'limit' , 1 ) ] ) ] ) ] ) #NEWLINE# self . assertEqual ( expected , started . command ) #NEWLINE# self . assertEqual ( 'pymongo_test' , started . database_name ) #NEWLINE# self . assertEqual ( 'delete' , started . command_name ) #NEWLINE# self . assertIsInstance ( started . request_id , int ) #NEWLINE# self . assertEqual ( self . client . address , started . connection_id ) #NEWLINE# self . assertIsInstance ( succeeded , monitoring . CommandSucceededEvent ) #NEWLINE# self . assertIsInstance ( succeeded . duration_micros , int ) #NEWLINE# self . assertEqual ( started . command_name , succeeded . command_name ) #NEWLINE# self . assertEqual ( started . request_id , succeeded . request_id ) #NEWLINE# self . assertEqual ( started . connection_id , succeeded . connection_id ) #NEWLINE# reply = succeeded . reply #NEWLINE# self . assertEqual ( 1 , reply . get ( 'ok' ) ) #NEWLINE# self . assertEqual ( 1 , reply . get ( 'n' ) ) #NEWLINE# self . assertEqual ( 0 , coll . count ( ) )