import unittest
try:
    from Products.SilvaMailing.htmlemail import HTMLEmail
except ImportError:
    from SilvaMailing.htmlemail import HTMLEmail
import email

class HTMLEmailTest(unittest.TestCase):
    def test_headers(self):
        e = HTMLEmail('foo@bar.com', 'bar@baz.com', 'html test mail',
                          '<html><body>foo</body></html>', 'foo')
        ser = e.serialize()
        msg = email.message_from_string(ser)
        parts = {}
        for part in msg.walk():
            ct = part.get_content_type()
            parts[ct] = part.get_payload(decode=True)

        self.assertEquals(3, len(parts.keys()))
        self.assertEquals('<html><body>foo</body></html>',
                          parts['text/html'])
        self.assertEquals('foo', parts['text/plain'])

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(HTMLEmailTest))
    return suite

if __name__ == '__main__':
    unittest.main()

