コード例 #1
0
    def scenario_does_not_use_auth(self, smtp_user):
        email = Email(from_addr='*****@*****.**', to_addr='*****@*****.**')

        send_email(email,
                   'smtp.domain.com',
                   25,
                   smtp_user=smtp_user,
                   smtp_pass='******')

        self.assertFalse(self.server.starttls.called)
        self.assertFalse(self.server.login.called)
コード例 #2
0
def create_email(subject='Subject',
                 from_addr='*****@*****.**',
                 to_addr='*****@*****.**',
                 reply_to_addr='*****@*****.**',
                 cc_addr='*****@*****.**',
                 body='Body'):
    """Creates a new `Email` from the given parameters."""
    return Email(subject=subject,
                 from_addr=from_addr,
                 to_addr=to_addr,
                 reply_to_addr=reply_to_addr,
                 cc_addr=cc_addr,
                 body=body)
コード例 #3
0
 def test_as_string_returns_correct_value(self):
     email = Email(subject='my subject',
                   from_addr='*****@*****.**',
                   to_addr='*****@*****.**',
                   reply_to_addr='*****@*****.**',
                   cc_addr='*****@*****.**')
     as_string = email.as_string
     self.assertIn('Content-Type: text/plain; charset="utf-8"', as_string)
     self.assertIn('my subject', as_string)
     self.assertIn('From: [email protected]', as_string)
     self.assertIn('To: [email protected]', as_string)
     self.assertIn('Reply-To: [email protected]', as_string)
     self.assertIn('CC: [email protected]', as_string)
コード例 #4
0
    def test_sends_email_correctly(self):
        FROM_ADDR = '*****@*****.**'
        TO_ADDR = '*****@*****.**'
        email = Email(from_addr=FROM_ADDR, to_addr=TO_ADDR)
        SMTP_SERVER = 'smtp.domain.com'
        SMTP_PORT = 25
        SMTP_USER = '******'
        SMTP_PASS = '******'

        send_email(email, SMTP_SERVER, SMTP_PORT, SMTP_USER, SMTP_PASS)

        self.smtplib_SMTP_mock.assert_called_once_with(SMTP_SERVER, SMTP_PORT)
        self.server.starttls.assert_called_once_with()
        self.server.login.assert_called_once_with(SMTP_USER, SMTP_PASS)
        self.server.sendmail.assert_called_once_with(FROM_ADDR, [TO_ADDR],
                                                     email.as_string)
        self.server.quit.assert_called_once_with()
コード例 #5
0
 def test_reply_to_addr_is_accessible_after_creation(self):
     email = Email(reply_to_addr='*****@*****.**')
     self.assertEqual(email.reply_to_addr, '*****@*****.**')
コード例 #6
0
 def test_sendmail_to_addrs_returns_two_addresses_when_there_is_to_addr_and_cc_addr(
         self):
     email = Email(to_addr='*****@*****.**', cc_addr='*****@*****.**')
     self.assertEqual(email.sendmail_to_addrs, ['*****@*****.**', '*****@*****.**'])
コード例 #7
0
 def test_sendmail_to_addrs_returns_singleton_list_when_there_is_only_to_addr(
         self):
     email = Email(to_addr='*****@*****.**')
     self.assertEqual(email.sendmail_to_addrs, ['*****@*****.**'])
コード例 #8
0
 def test_sendmail_to_addrs_is_empty_when_there_is_no_to_addr(self):
     email = Email()
     self.assertEqual(email.sendmail_to_addrs, [])
コード例 #9
0
 def test_from_addr_is_empty_after_creation(self):
     email = Email()
     self.assertEqual(len(email.from_addr), 0)
コード例 #10
0
 def test_from_addr_is_accessible_after_creation(self):
     email = Email(from_addr='*****@*****.**')
     self.assertEqual(email.from_addr, '*****@*****.**')
コード例 #11
0
 def test_body_can_be_changed_after_creation(self):
     email = Email()
     email.body = 'new body'
     self.assertEqual(email.body, 'new body')
コード例 #12
0
 def test_subject_can_be_changed_after_creation(self):
     email = Email()
     email.subject = 'new subject'
     self.assertEqual(email.subject, 'new subject')
コード例 #13
0
 def test_subject_is_accessible_after_creation(self):
     email = Email(subject='my subject')
     self.assertEqual(email.subject, 'my subject')
コード例 #14
0
 def test_body_is_empty_after_creation(self):
     email = Email()
     self.assertEqual(len(email.body), 0)
コード例 #15
0
 def test_reply_to_addr_can_be_changed_after_creation(self):
     email = Email()
     email.reply_to_addr = '*****@*****.**'
     self.assertEqual(email.reply_to_addr, '*****@*****.**')
コード例 #16
0
 def test_subject_is_empty_after_creation(self):
     email = Email()
     self.assertEqual(len(email.subject), 0)
コード例 #17
0
 def test_reply_to_addr_is_empty_after_creation(self):
     email = Email()
     self.assertEqual(len(email.reply_to_addr), 0)
コード例 #18
0
 def test_body_is_accessible_after_creation(self):
     email = Email(body='my body')
     self.assertEqual(email.body, 'my body')