#NEWLINE# def test_send_email_does_not_resend_within_duplicate_interval( self ) : #NEWLINE# #INDENT# can_send_emails_ctx = self . swap ( feconf , 'CAN_SEND_EMAILS_TO_USERS' , True ) #NEWLINE# duplicate_email_ctx = self . swap ( feconf , 'DUPLICATE_EMAIL_INTERVAL_MINS' , 2 ) #NEWLINE# logged_errors = [ ] #NEWLINE# def _log_error_for_tests( error_message ) : #NEWLINE# #INDENT# logged_errors . append ( error_message ) #NEWLINE# #UNINDENT# log_new_error_counter = test_utils . CallCounter ( _log_error_for_tests ) #NEWLINE# log_new_error_ctx = self . swap ( email_manager , 'log_new_error' , log_new_error_counter ) #NEWLINE# with can_send_emails_ctx , duplicate_email_ctx , log_new_error_ctx : #NEWLINE# #INDENT# config_services . set_property ( self . admin_id , email_manager . EMAIL_SENDER_NAME . name , 'Email Sender' ) #NEWLINE# all_models = email_models . SentEmailModel . get_all ( ) . fetch ( ) #NEWLINE# self . assertEqual ( len ( all_models ) , 0 ) #NEWLINE# email_manager . _send_email ( self . new_user_id , feconf . SYSTEM_COMMITTER_ID , feconf . EMAIL_INTENT_SIGNUP , 'Email Subject' , 'Email Body' ) #NEWLINE# messages = self . mail_stub . get_sent_messages ( to = self . NEW_USER_EMAIL ) #NEWLINE# self . assertEqual ( 1 , len ( messages ) ) #NEWLINE# all_models = email_models . SentEmailModel . get_all ( ) . fetch ( ) #NEWLINE# self . assertEqual ( len ( all_models ) , 1 ) #NEWLINE# self . assertEqual ( log_new_error_counter . times_called , 0 ) #NEWLINE# email_manager . _send_email ( self . new_user_id , feconf . SYSTEM_COMMITTER_ID , feconf . EMAIL_INTENT_SIGNUP , 'Email Subject' , 'Email Body' ) #NEWLINE# self . assertEqual ( log_new_error_counter . times_called , 1 ) #NEWLINE# self . assertRegexpMatches ( duplicate_email_ctx [ 0 ] , 'Duplicate email' ) #NEWLINE# messages = self . mail_stub . get_sent_messages ( to = self . NEW_USER_EMAIL ) #NEWLINE# self . assertEqual ( 1 , len ( messages ) ) #NEWLINE# all_models = email_models . SentEmailModel . get_all ( ) . fetch ( ) #NEWLINE# self . assertEqual ( len ( all_models ) , 1 )