#NEWLINE# def test_actions_log_entries( self ) : #NEWLINE# #INDENT# invoice = InvoiceFactory . create ( ) #NEWLINE# url = reverse ( 'admin:silver_invoice_changelist' ) #NEWLINE# mock_log_entry = MagicMock ( ) #NEWLINE# mock_log_action = MagicMock ( ) #NEWLINE# mock_log_entry . objects . log_action = mock_log_action #NEWLINE# mock_action = MagicMock ( return_value = MagicMock ( series_number = 'aaa' ) ) #NEWLINE# mock_invoice = MagicMock ( ) #NEWLINE# mock_invoice . issue = mock_action #NEWLINE# mock_invoice . cancel = mock_action #NEWLINE# mock_invoice . pay = mock_action #NEWLINE# mock_invoice . clone_into_draft = mock_action #NEWLINE# with patch . multiple ( 'silver.admin' , LogEntry = mock_log_entry , Invoice = mock_invoice ) : #NEWLINE# #INDENT# actions = [ 'issue' , 'pay' , 'cancel' , 'clone' ] #NEWLINE# for action in actions : #NEWLINE# #INDENT# self . admin . post ( url , { #NEWLINE# #INDENT# 'action' : action , #NEWLINE# '_selected_action' : [ '1' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert mock_action . call_count #NEWLINE# mock_action . reset_mock ( ) #NEWLINE# if ( action == 'clone' ) : #NEWLINE# #INDENT# action = 'clone_into_draft' #NEWLINE# #UNINDENT# mock_log_action . assert_called_with ( user_id = 1 , content_type_id = ContentType . objects . get_for_model ( invoice ) . pk , object_id = 1 , object_repr = unicode ( invoice ) , action_flag = CHANGE , change_message = '{action} action initiated by user.' . format ( action = action . capitalize ( ) . replace ( '_' , ' ' ) ) )