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)
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)
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)
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()
def test_reply_to_addr_is_accessible_after_creation(self): email = Email(reply_to_addr='*****@*****.**') self.assertEqual(email.reply_to_addr, '*****@*****.**')
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, ['*****@*****.**', '*****@*****.**'])
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, ['*****@*****.**'])
def test_sendmail_to_addrs_is_empty_when_there_is_no_to_addr(self): email = Email() self.assertEqual(email.sendmail_to_addrs, [])
def test_from_addr_is_empty_after_creation(self): email = Email() self.assertEqual(len(email.from_addr), 0)
def test_from_addr_is_accessible_after_creation(self): email = Email(from_addr='*****@*****.**') self.assertEqual(email.from_addr, '*****@*****.**')
def test_body_can_be_changed_after_creation(self): email = Email() email.body = 'new body' self.assertEqual(email.body, 'new body')
def test_subject_can_be_changed_after_creation(self): email = Email() email.subject = 'new subject' self.assertEqual(email.subject, 'new subject')
def test_subject_is_accessible_after_creation(self): email = Email(subject='my subject') self.assertEqual(email.subject, 'my subject')
def test_body_is_empty_after_creation(self): email = Email() self.assertEqual(len(email.body), 0)
def test_reply_to_addr_can_be_changed_after_creation(self): email = Email() email.reply_to_addr = '*****@*****.**' self.assertEqual(email.reply_to_addr, '*****@*****.**')
def test_subject_is_empty_after_creation(self): email = Email() self.assertEqual(len(email.subject), 0)
def test_reply_to_addr_is_empty_after_creation(self): email = Email() self.assertEqual(len(email.reply_to_addr), 0)
def test_body_is_accessible_after_creation(self): email = Email(body='my body') self.assertEqual(email.body, 'my body')