예제 #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')