Back to index

plone3  3.1.7
test_headerparsing.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 #
00003 # Tests the email validation
00004 #
00005 
00006 import os, sys
00007 if __name__ == '__main__':
00008     execfile(os.path.join(sys.path[0], 'framework.py'))
00009 
00010 from common import *
00011 from DateTime import DateTime
00012 from email.MIMEText import MIMEText
00013 import email.Message
00014 from Products.SecureMailHost import mail
00015 
00016 tests = []
00017 
00018 class TestHeaderParsing(ZopeTestCase.ZopeTestCase):
00019 
00020     def afterSetUp(self):
00021         self.mailhost = SecureMailBase('securemailhost', '')
00022 
00023     def test_header_cc_bcc(self):
00024         # test if cc and bcc addresses are added to the server To
00025         send = self.mailhost.secureSend
00026         
00027         msg = email.MIMEText.MIMEText('body', 'plain', 'us-ascii')
00028         mto =  "to@example.org"
00029         mfrom = "from@example.org"
00030         mbcc = "bcc@example.org"
00031         mcc = "cc@example.org"
00032         
00033         result = send(msg, mto=mto, mfrom=mfrom, subject='test',
00034                       mcc=mcc, mbcc = mbcc, debug=True)
00035 
00036         self.failUnless(isinstance(result, mail.Mail),
00037                         'Result is not a mail.Mail instance')
00038         
00039         eto = ",".join(result.mto)
00040         msg = result.message
00041         
00042         for addr in mto, mbcc, mcc:
00043             if eto.find(addr) == -1:
00044                 self.fail("%s not in %s " % (addr, eto))
00045         
00046         self.failUnlessEqual(msg['From'], mfrom)
00047         self.failUnlessEqual(msg['Cc'], mcc)
00048         self.failUnlessEqual(msg['Bcc'], mbcc)
00049         self.failUnlessEqual(msg['To'], mto)
00050 
00051 tests.append(TestHeaderParsing)
00052 
00053 
00054 def test_suite():
00055     from unittest import TestSuite, makeSuite
00056     suite = TestSuite()
00057     for test in tests:
00058         suite.addTest(makeSuite(test))
00059     return suite
00060 
00061 if __name__ == '__main__':
00062     framework()