Esempio n. 1
0
 def testCloseServerSessionMustInvokeTheSessionQuitMethod(self):
     mail_send_preparation = MailSessionHelper()
     session = Mock()
     
     mail_send_preparation.close_server_session(session)
     
     session.quit.assert_called()
Esempio n. 2
0
class AdministratorMail(object):
    def __init__(self):
        logger_manager = LoggerManager()
        self.log = logger_manager.get_new_logger("administrator mail")
        self.mail_handle_strategy = MailHandleRESTAPIStrategy(
            http_serializer=HTTP_SERIALIZER,
            auth_user=settings.SERIALIZER_AUTH_USER,
            auth_pass=settings.SERIALIZER_AUTH_PASS)
        self.session_helper = MailSessionHelper(
            email_host=settings.EMAIL_HOST,
            email_port=settings.EMAIL_PORT,
            email_host_user=settings.EMAIL_HOST_USER,
            email_host_password=settings.EMAIL_HOST_PASSWORD)

    def send_mails(self):
        mails = self.mail_handle_strategy.get_pending_mails()
        if (mails is None or len(mails) == 0):
            self.log.info("There are not mails to be delivered")
        else:
            self.log.info("Found %d mails awaiting sending.", len(mails))
            session = self.session_helper.get_server_session()
            for mail in mails:
                session.sendmail(
                    settings.EMAIL_HOST_USER, mail.recipient,
                    mail.build_to_send_from_host(settings.EMAIL_HOST_USER))
                self.log.info("Mail sent to %s (subject: %s)", mail.recipient,
                              mail.subject)
                response = self.mail_handle_strategy.request_mail_deletion(
                    mail)
                self.log.info("Delete response: %s", str(response))
            self.session_helper.close_server_session(session)
Esempio n. 3
0
    def testCloseServerSessionMustInvokeTheSessionQuitMethod(self):
        mail_send_preparation = MailSessionHelper()
        session = Mock()

        mail_send_preparation.close_server_session(session)

        session.quit.assert_called()
Esempio n. 4
0
class AdministratorMail(object):

    def __init__(self):
        logger_manager = LoggerManager()
        self.log = logger_manager.get_new_logger("administrator mail")
        self.mail_handle_strategy = MailHandleRESTAPIStrategy(
                                                          http_serializer=HTTP_SERIALIZER, 
                                                          auth_user=settings.SERIALIZER_AUTH_USER, 
                                                          auth_pass=settings.SERIALIZER_AUTH_PASS)
        self.session_helper = MailSessionHelper(email_host=settings.EMAIL_HOST, 
                                                         email_port=settings.EMAIL_PORT, 
                                                         email_host_user=settings.EMAIL_HOST_USER, 
                                                         email_host_password=settings.EMAIL_HOST_PASSWORD)
        
    def send_mails(self):
        mails = self.mail_handle_strategy.get_pending_mails()
        if (mails is None or len(mails)==0):
            self.log.info("There are not mails to be delivered")
        else:
            self.log.info("Found %d mails awaiting sending.", len(mails))
            session = self.session_helper.get_server_session()
            for mail in mails:
                session.sendmail(settings.EMAIL_HOST_USER, mail.recipient, mail.build_to_send_from_host(settings.EMAIL_HOST_USER))
                self.log.info("Mail sent to %s (subject: %s)", mail.recipient, mail.subject)
                response = self.mail_handle_strategy.request_mail_deletion(mail)
                self.log.info("Delete response: %s", str(response))
            self.session_helper.close_server_session(session)
Esempio n. 5
0
 def __init__(self):
     logger_manager = LoggerManager()
     self.log = logger_manager.get_new_logger("administrator mail")
     self.mail_handle_strategy = MailHandleRESTAPIStrategy(
         http_serializer=HTTP_SERIALIZER,
         auth_user=settings.SERIALIZER_AUTH_USER,
         auth_pass=settings.SERIALIZER_AUTH_PASS)
     self.session_helper = MailSessionHelper(
         email_host=settings.EMAIL_HOST,
         email_port=settings.EMAIL_PORT,
         email_host_user=settings.EMAIL_HOST_USER,
         email_host_password=settings.EMAIL_HOST_PASSWORD)
Esempio n. 6
0
 def testMailSendPreparationMustSetUpAProperlyConfiguredSession(self):
     mail_send_preparation = MailSessionHelper()
     smtplib_mock = Mock()
     return_value = Mock()
     smtplib_mock.SMTP.return_value = return_value
     mail_send_preparation.smtplib = smtplib_mock
     
     result = mail_send_preparation.get_server_session()
     
     smtplib_mock.SMTP.assert_called()
     return_value.ehlo.assert_called()
     return_value.starttls.assert_called()
     return_value.ehlo.assert_called()
     return_value.login.assert_called()
     self.assertEqual(result, return_value)
Esempio n. 7
0
    def testMailSendPreparationMustSetUpAProperlyConfiguredSession(self):
        mail_send_preparation = MailSessionHelper()
        smtplib_mock = Mock()
        return_value = Mock()
        smtplib_mock.SMTP.return_value = return_value
        mail_send_preparation.smtplib = smtplib_mock

        result = mail_send_preparation.get_server_session()

        smtplib_mock.SMTP.assert_called()
        return_value.ehlo.assert_called()
        return_value.starttls.assert_called()
        return_value.ehlo.assert_called()
        return_value.login.assert_called()
        self.assertEqual(result, return_value)
Esempio n. 8
0
 def __init__(self):
     logger_manager = LoggerManager()
     self.log = logger_manager.get_new_logger("administrator mail")
     self.mail_handle_strategy = MailHandleRESTAPIStrategy(
                                                       http_serializer=HTTP_SERIALIZER, 
                                                       auth_user=settings.SERIALIZER_AUTH_USER, 
                                                       auth_pass=settings.SERIALIZER_AUTH_PASS)
     self.session_helper = MailSessionHelper(email_host=settings.EMAIL_HOST, 
                                                      email_port=settings.EMAIL_PORT, 
                                                      email_host_user=settings.EMAIL_HOST_USER, 
                                                      email_host_password=settings.EMAIL_HOST_PASSWORD)