From e72e8ab515931f294523e836693eb76358fed240 Mon Sep 17 00:00:00 2001 From: Patrick Maia Date: Thu, 23 Oct 2014 19:15:03 -0300 Subject: Card #30 - handles alternative bodies on InputMail --- service/test/unit/adapter/mail_test.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'service/test') diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py index b4e19017..3bec6fc7 100644 --- a/service/test/unit/adapter/mail_test.py +++ b/service/test/unit/adapter/mail_test.py @@ -104,6 +104,19 @@ class InputMailTest(unittest.TestCase): 'tags': ['sent'] } + multipart_mail_dict = lambda x: { + 'body': [{'content-type': 'plain', 'raw': 'Hello world!'}, + {'content-type': 'html', 'raw': '

Hello html world!

'}], + 'header': { + 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], + 'to': ['to@pixelated.org', 'anotherto@pixelated.org'], + 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'], + 'subject': 'Oi', + }, + 'ident': '', + 'tags': ['sent'] + } + def test_to_mime_multipart_should_add_blank_fields(self): pixelated.support.date.iso_now = lambda: 'date now' @@ -138,3 +151,12 @@ class InputMailTest(unittest.TestCase): smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format() self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org") + + def test_to_mime_multipart_handles_alternative_bodies(self): + mime_multipart = InputMail.from_dict(self.multipart_mail_dict()).to_mime_multipart() + + part_one = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello world!' + part_two = 'Content-Type: text/html; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\n

Hello html world!

' + + self.assertRegexpMatches(mime_multipart.as_string(), part_one) + self.assertRegexpMatches(mime_multipart.as_string(), part_two) -- cgit v1.2.3