test_bounce.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """Test cases for bounce message generation
  4. """
  5. from twisted.trial import unittest
  6. from twisted.mail import bounce
  7. import cStringIO
  8. import email.message
  9. import email.parser
  10. class BounceTests(unittest.TestCase):
  11. """
  12. testcases for bounce message generation
  13. """
  14. def testBounceFormat(self):
  15. from_, to, s = bounce.generateBounce(cStringIO.StringIO('''\
  16. From: Moshe Zadka <moshez@example.com>
  17. To: nonexistent@example.org
  18. Subject: test
  19. '''), 'moshez@example.com', 'nonexistent@example.org')
  20. self.assertEqual(from_, '')
  21. self.assertEqual(to, 'moshez@example.com')
  22. emailParser = email.parser.Parser()
  23. mess = emailParser.parse(cStringIO.StringIO(s))
  24. self.assertEqual(mess['To'], 'moshez@example.com')
  25. self.assertEqual(mess['From'], 'postmaster@example.org')
  26. self.assertEqual(mess['subject'], 'Returned Mail: see transcript for details')
  27. def testBounceMIME(self):
  28. pass