def test_should_send_email_to_outbox(self): cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>') m = self.get_latest_email() self.assertTrue('*****@*****.**' in m.to, 'to address not found') self.assertEqual(m.subject, 'Test') self.assertTrue('<h1>Test</h1>' in m.message().as_string())
def test_should_contain_reply_to_from_cms_settings(self): s = Settings() s.enquiry_reply = '*****@*****.**' s.save() cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>') m = self.get_latest_email() self.assertTrue(m.extra_headers.get('Reply-To'), '*****@*****.**')
def test_should_decode_utf8_multipart(self): cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>') m = self.get_latest_email() text = get_decoded_email_body(m.message().as_string()) self.assertEqual(text, '<h1>Test</h1>') try: text.decode('utf-8') except UnicodeError: self.assertTrue( False, 'decoded email message body is not UTF-8 encoded byte string.')
def test_ignore_encoding_if_no_encoding_is_known_for_part(self): cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>') m = self.get_latest_email() raw_message = m.message().as_string() raw_message = re.sub(r'text\/plain; charset\="utf-8"', '', raw_message) text = get_decoded_email_body(raw_message) self.assertEqual(text, '<h1>Test</h1>') try: text.decode('utf-8') except UnicodeError: self.assertTrue( False, 'decoded email message body is not UTF-8 encoded byte string.')
def test_should_add_single_attachement(self): filename = os.path.join(settings.BASE_PATH, 'templates', 'testapp', 'attachments', 'a.txt') cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>', filename) m = self.get_latest_email() self.assertTrue('*****@*****.**' in m.to, 'to address not found') self.assertEqual(m.subject, 'Test') self.assertTrue('<h1>Test</h1>' in m.message().as_string()) self.assertEqual(1, len(m.attachments)) # attachment filename, content, _ = m.attachments[0] self.assertEqual('a.txt', filename) self.assertEqual('This is an email attachment.', content)
def test_requires_cubane_cms_module(self): with self.assertRaises(ValueError): cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>')
def test_should_raise_exception_if_attachment_file_does_not_exist(self): with self.assertRaisesRegexp(IOError, 'No such file or directory'): cubane_send_mail('*****@*****.**', 'Test', '<h1>Test</h1>', 'does-not-exist')