Beispiel #1
0
    def test_send_email(self, smtp):
        action = std.SendEmailAction(
            from_addr=self.from_addr,
            to_addrs=self.to_addrs,
            smtp_server=self.smtp_server,
            smtp_password=None,
            subject=self.subject,
            body=self.body
        )

        action.run(self.ctx)

        smtp.assert_called_once_with(self.smtp_server)

        sendmail = smtp.return_value.sendmail

        self.assertTrue(sendmail.called, "should call sendmail")
        self.assertEqual(
            self.from_addr, sendmail.call_args[1]['from_addr'])
        self.assertEqual(
            self.to_addrs, sendmail.call_args[1]['to_addrs'])

        message = parser.Parser().parsestr(sendmail.call_args[1]['msg'])

        self.assertEqual(self.from_addr, message['from'])
        self.assertEqual(self.to_addrs_str, message['to'])
        self.assertEqual(
            self.subject,
            decode_header(message['subject'])[0][0].decode('utf-8')
        )

        self.assertEqual(
            self.body,
            base64.b64decode(message.get_payload()).decode('utf-8')
        )
Beispiel #2
0
    def test_send_email_with_reply_to(self, smtp):
        action = std.SendEmailAction(
            from_addr=self.from_addr,
            to_addrs=self.to_addrs,
            reply_to=self.reply_to,
            bcc_addrs=self.bcc_addrs,
            smtp_server=self.smtp_server,
            smtp_password=None,
            subject=self.subject,
            body=self.body
        )

        action.run(self.ctx)

        smtp.assert_called_once_with(self.smtp_server)

        sendmail = smtp.return_value.sendmail

        self.assertTrue(sendmail.called, "should call sendmail")
        self.assertEqual(
            self.from_addr, sendmail.call_args[1]['from_addr'])

        message = parser.Parser().parsestr(sendmail.call_args[1]['msg'])

        self.assertEqual(self.from_addr, message['from'])
        self.assertEqual(self.to_addrs_str, message['to'])
        self.assertEqual(self.reply_to_str, message['reply-to'])
    def test_with_one_to_addr(self, smtp):
        to_addr = ["*****@*****.**"]
        smtp_password = "******"

        action = std.SendEmailAction(self.from_addr, to_addr, self.smtp_server,
                                     smtp_password, self.subject, self.body)
        action.run()
Beispiel #4
0
 def test_send_email_real(self):
     action = std.SendEmailAction(from_addr=self.from_addr,
                                  to_addrs=self.to_addrs,
                                  smtp_server=self.smtp_server,
                                  smtp_password=None,
                                  subject=self.subject,
                                  body=self.body)
     action.run(self.ctx)
Beispiel #5
0
 def test_with_mutli_to_addrs(self, smtp):
     smtp_password = "******"
     action = std.SendEmailAction(from_addr=self.from_addr,
                                  to_addrs=self.to_addrs,
                                  smtp_server=self.smtp_server,
                                  smtp_password=smtp_password,
                                  subject=self.subject,
                                  body=self.body)
     action.run(self.ctx)
Beispiel #6
0
    def test_with_password_real(self):
        self.to_addrs = ["*****@*****.**"]
        self.smtp_server = 'mail.example.com:25'
        self.from_addr = "*****@*****.**"
        self.smtp_password = '******'

        action = std.SendEmailAction(self.from_addr, self.to_addrs,
                                     self.smtp_server, self.smtp_password,
                                     self.subject, self.body)

        action.run()
    def test_with_password_real(self):
        self.params['to'] = ["*****@*****.**"]
        self.settings = {
            'smtp_server': 'smtp.gmail.com:587',
            'from': "*****@*****.**",
            'password': '******'
        }

        action = std.SendEmailAction(self.params, self.settings)

        action.run()
    def test_exception(self, log):
        self.params['smtp_server'] = "wrong host"

        action = std.SendEmailAction(self.params, self.settings)

        try:
            action.run()
        except exc.ActionException:
            pass
        else:
            self.assertFalse("Must throw exception.")
Beispiel #9
0
    def test_exception(self, log):
        self.smtp_server = "wrong host"

        action = std.SendEmailAction(self.from_addr, self.to_addrs,
                                     self.smtp_server, None, self.subject,
                                     self.body)

        try:
            action.run()
        except exc.ActionException:
            pass
        else:
            self.assertFalse("Must throw exception.")
    def test_with_password(self, smtp):
        self.settings['password'] = "******"

        action = std.SendEmailAction(self.params, self.settings)

        action.run()

        smtpmock = smtp.return_value
        calls = [
            call.ehlo(),
            call.starttls(),
            call.ehlo(),
            call.login(self.settings['from'], self.settings['password'])
        ]

        smtpmock.assert_has_calls(calls)
        self.assertTrue(smtpmock.sendmail.called, "should call sendmail")
Beispiel #11
0
    def test_with_password(self, smtp):
        self.smtp_password = "******"

        action = std.SendEmailAction(self.from_addr, self.to_addrs,
                                     self.smtp_server, self.smtp_password,
                                     self.subject, self.body)

        action.run()

        smtpmock = smtp.return_value
        calls = [
            mock.call.ehlo(),
            mock.call.starttls(),
            mock.call.ehlo(),
            mock.call.login(self.from_addr, self.smtp_password)
        ]

        smtpmock.assert_has_calls(calls)
        self.assertTrue(smtpmock.sendmail.called, "should call sendmail")
    def test_send_email(self, smtp):
        action = std.SendEmailAction(self.params, self.settings)

        action.run()

        smtp.assert_called_once_with(self.settings['smtp_server'])

        sendmail = smtp.return_value.sendmail

        self.assertTrue(sendmail.called, "should call sendmail")
        self.assertEqual(sendmail.call_args[1]['from_addr'],
                         self.settings['from'])
        self.assertEqual(sendmail.call_args[1]['to_addrs'], self.to_addrs)

        message = Parser().parsestr(sendmail.call_args[1]['msg'])

        self.assertEqual(self.settings['from'], message['from'])
        self.assertEqual(self.to_addrs, message['to'])
        self.assertEqual(self.params['subject'], message['subject'])
        self.assertEqual(self.params['body'], message.get_payload())
Beispiel #13
0
    def test_send_email(self, smtp):
        action = std.SendEmailAction(self.from_addr, self.to_addrs,
                                     self.smtp_server, None, self.subject,
                                     self.body)

        action.run()

        smtp.assert_called_once_with(self.smtp_server)

        sendmail = smtp.return_value.sendmail

        self.assertTrue(sendmail.called, "should call sendmail")
        self.assertEqual(sendmail.call_args[1]['from_addr'], self.from_addr)
        self.assertEqual(sendmail.call_args[1]['to_addrs'], self.to_addrs_str)

        message = parser.Parser().parsestr(sendmail.call_args[1]['msg'])

        self.assertEqual(self.from_addr, message['from'])
        self.assertEqual(self.to_addrs_str, message['to'])
        self.assertEqual(self.subject, message['subject'])
        self.assertEqual(self.body, message.get_payload())
Beispiel #14
0
 def test_send_email_real(self):
     action = std.SendEmailAction(self.from_addr, self.to_addrs,
                                  self.smtp_server, None, self.subject,
                                  self.body)
     action.run()
 def test_send_email_real(self):
     action = std.SendEmailAction(self.params, self.settings)
     action.run()