def test_send_mail_autofield_text_template(self): """Tests the seend_email but without especifing the text template so it will take the same name as the html with different extension """ send_mail( MailTest.SUBJECT, MailTest.HTML_TEMPLATE, MailTest.CONTEXT, MailTest.FROM_EMAIL, MailTest.RECIPIENT_LIST ) # Check that is correct # 1 read email file email_file = read_single_file(TMP_DIR) # 2 Check headers data: content_type = "Content-Type: multipart/alternative;" subject = "Subject: {0}".format(MailTest.SUBJECT) sender = "From: {0}".format(MailTest.FROM_EMAIL) receiver = "To: {0}".format(MailTest.RECIPIENT_LIST[0]) self.assertTrue(content_type in email_file) self.assertTrue(subject in email_file) self.assertTrue(sender in email_file) self.assertTrue(receiver in email_file) # 3 Check that there are 2 types of email (text and HTML) plain = 'Content-Type: text/plain; charset="utf-8"' html = 'Content-Type: text/html; charset="utf-8"' self.assertTrue(plain in email_file) self.assertTrue(html in email_file) # 4 Check text content self.assertTrue(MailTest.CORRECT_TEXT in email_file) # 5 Check html content self.assertTrue(MailTest.CORRECT_HTML in email_file)
def test_send_mail_autofield_text_template_with_strip_tags(self): """Tests the send_email but without especifing the text template so it will take the same name as the html without extension, but This doesn't exist so it strips the tags """ send_mail(MailTest.SUBJECT, "test/test2.html", MailTest.CONTEXT, MailTest.FROM_EMAIL, MailTest.RECIPIENT_LIST) # Check that is correct # 1 read email file email_file = read_single_file(TMP_DIR) # 2 Check headers data: content_type = "Content-Type: multipart/alternative;" subject = "Subject: {0}".format(MailTest.SUBJECT) sender = "From: {0}".format(MailTest.FROM_EMAIL) receiver = "To: {0}".format(MailTest.RECIPIENT_LIST[0]) self.assertTrue(content_type in email_file) self.assertTrue(subject in email_file) self.assertTrue(sender in email_file) self.assertTrue(receiver in email_file) # 3 Check that there are 2 types of email (text and HTML) plain = 'Content-Type: text/plain; charset="utf-8"' html = 'Content-Type: text/html; charset="utf-8"' self.assertTrue(plain in email_file) self.assertTrue(html in email_file) # 4 Check text content correct_text = ( " Summary\n This is a test in Django an" + "d email with template using dancymail\n\n \n powe" + "red by Python, Django and Django fancymail" ) self.assertTrue(correct_text in email_file) # 5 Check html content self.assertTrue(MailTest.CORRECT_HTML in email_file)