#NEWLINE# @ mock . patch ( 'website.mails.send_mail' ) #NEWLINE# def test_send_users_email_called_with_correct_args( self , mock_send_mail ) : #NEWLINE# #INDENT# send_type = 'email_transactional' #NEWLINE# d = factories . NotificationDigestFactory ( user_id = factories . UserFactory ( ) . _id , send_type = send_type , timestamp = datetime . datetime . utcnow ( ) , message = 'Hello' , node_lineage = [ factories . ProjectFactory ( ) . _id ] ) #NEWLINE# d . save ( ) #NEWLINE# user_groups = get_users_emails ( send_type ) #NEWLINE# send_users_email ( send_type ) #NEWLINE# assert_true ( mock_send_mail . called ) #NEWLINE# assert_equals ( mock_send_mail . call_count , len ( user_groups ) ) #NEWLINE# last_user_index = ( len ( user_groups ) - 1 ) #NEWLINE# user = User . load ( user_groups [ last_user_index ] [ 'user_id' ] ) #NEWLINE# email_notification_ids = [ message [ '_id' ] for message in user_groups [ last_user_index ] [ 'info' ] ] #NEWLINE# ( args , kwargs ) = mock_send_mail . call_args #NEWLINE# assert_equal ( kwargs [ 'to_addr' ] , user . username ) #NEWLINE# assert_equal ( kwargs [ 'mimetype' ] , 'html' ) #NEWLINE# assert_equal ( kwargs [ 'mail' ] , mails . DIGEST ) #NEWLINE# assert_equal ( kwargs [ 'name' ] , user . fullname ) #NEWLINE# message = group_by_node ( self [ last_user_index ] [ 'info' ] ) #NEWLINE# assert_equal ( kwargs [ 'message' ] , message ) #NEWLINE# assert_equal ( kwargs [ 'callback' ] , remove_notifications ( email_notification_ids = email_notification_ids ) )