#NEWLINE# @ patch ( 'eventtracker.tasks._get_carrot_object' ) #NEWLINE# @ patch ( 'eventtracker.models.get_mongo_collection' ) #NEWLINE# @ patch ( 'eventtracker.models.save_event' ) #NEWLINE# def test_collect_events_calls_save_event_for_every_event_in_queue( save_event , get_mongo_collection , get_carrot_object ) : #NEWLINE# #INDENT# collection = Mock ( ) #NEWLINE# get_mongo_collection . return_value = collection #NEWLINE# ( t1 , t2 ) = ( ( time ( ) - 1 ) , time ( ) ) #NEWLINE# ( m1 , m2 ) = ( Mock ( ) , Mock ( ) ) #NEWLINE# ( m1 . decode . return_value , m2 . decode . return_value ) = ( ( 'event' , t1 , { #NEWLINE# #INDENT# 'some' : 'params' , #NEWLINE# #UNINDENT# } ) , ( 'other_event' , t2 , { #NEWLINE# #INDENT# 'other' : 'params' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# consumer = Mock ( ) #NEWLINE# get_carrot_object . return_value = consumer #NEWLINE# consumer . iterqueue . return_value = [ m1 , m2 ] #NEWLINE# collect_events ( ) #NEWLINE# tools . assert_equals ( [ ( 'decode' , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , ( 'ack' , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ] , m1 . method_calls ) #NEWLINE# tools . assert_equals ( [ ( 'decode' , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , ( 'ack' , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ] , m2 . method_calls ) #NEWLINE# tools . assert_equals ( 1 , consumer . iterqueue . call_count ) #NEWLINE# tools . assert_equals ( 2 , save_event . call_count ) #NEWLINE# tools . assert_equals ( [ ( ( collection , 'event' , t1 , { #NEWLINE# #INDENT# 'some' : 'params' , #NEWLINE# #UNINDENT# } ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) , ( ( collection , 'other_event' , get_mongo_collection , { #NEWLINE# #INDENT# 'other' : 'params' , #NEWLINE# #UNINDENT# } ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ] , save_event . call_args_list )