Exemple #1
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)
Exemple #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)
Exemple #3
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)
 def testDeleteMailsMustCallAnHttpRequestUsingDeleteMethod(self):
     http_serializer=TestMailFetchFromRESTAPI.HTTP_SERIALIZER_URL
     auth_user='******'
     auth_pass='******'
     
     mail_handle_rest_api_strategy = MailHandleRESTAPIStrategy(http_serializer, auth_user, auth_pass)
     requests_mock = Mock()
     mail_handle_rest_api_strategy.requests = requests_mock
     mail = Mock()
     mail.id = 1
     
     mail_handle_rest_api_strategy.request_mail_deletion(mail)
     
     requests_mock.delete.assert_called()
Exemple #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)
 def testGetMailsMustCallAnHttpRequestUsingGetMethod(self):
     http_serializer=TestMailFetchFromRESTAPI.HTTP_SERIALIZER_URL
     auth_user='******'
     auth_pass='******'
     
     mail_handle_rest_api_strategy = MailHandleRESTAPIStrategy(http_serializer, auth_user, auth_pass)
     json_translator_mock = Mock()
     mail_handle_rest_api_strategy.json_translator = json_translator_mock
     requests_mock = Mock()
     mail_handle_rest_api_strategy.requests = requests_mock
     mail_request = Mock()
     mail_request.status_code = 204
     requests_mock.get.return_value = mail_request
     
     mail_handle_rest_api_strategy.get_pending_mails()
     
     requests_mock.get.assert_called_once_with(http_serializer, headers={"KEY":settings.DAEMON_KEY})
 def testGetMailsMustCallAnHttpRequestAndSendTheResponseToJsonTranslator(self):
     http_serializer=TestMailFetchFromRESTAPI.HTTP_SERIALIZER_URL
     auth_user='******'
     auth_pass='******'
     
     mail_handle_rest_api_strategy = MailHandleRESTAPIStrategy(http_serializer, auth_user, auth_pass)
     json_translator_mock = Mock()
     mail_handle_rest_api_strategy.json_translator = json_translator_mock
     requests_mock = Mock()
     mail_handle_rest_api_strategy.requests = requests_mock
     mail_request = Mock()
     requests_mock.get.return_value = mail_request
     mail_request.status_code = 200
     mail_request.content = Mock()
     
     mail_handle_rest_api_strategy.get_pending_mails()
     
     json_translator_mock.get_mails_list.assert_called()