test_mailmail.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.mail.scripts.mailmail}, the implementation of the
  5. command line program I{mailmail}.
  6. """
  7. import sys
  8. from StringIO import StringIO
  9. from twisted.trial.unittest import TestCase
  10. from twisted.mail.scripts.mailmail import parseOptions
  11. class OptionsTests(TestCase):
  12. """
  13. Tests for L{parseOptions} which parses command line arguments and reads
  14. message text from stdin to produce an L{Options} instance which can be
  15. used to send a message.
  16. """
  17. def test_unspecifiedRecipients(self):
  18. """
  19. If no recipients are given in the argument list and there is no
  20. recipient header in the message text, L{parseOptions} raises
  21. L{SystemExit} with a string describing the problem.
  22. """
  23. self.addCleanup(setattr, sys, 'stdin', sys.stdin)
  24. sys.stdin = StringIO(
  25. 'Subject: foo\n'
  26. '\n'
  27. 'Hello, goodbye.\n')
  28. exc = self.assertRaises(SystemExit, parseOptions, [])
  29. self.assertEqual(exc.args, ('No recipients specified.',))
  30. def test_listQueueInformation(self):
  31. """
  32. The I{-bp} option for listing queue information is unsupported and
  33. if it is passed to L{parseOptions}, L{SystemExit} is raised.
  34. """
  35. exc = self.assertRaises(SystemExit, parseOptions, ['-bp'])
  36. self.assertEqual(exc.args, ("Unsupported option.",))
  37. def test_stdioTransport(self):
  38. """
  39. The I{-bs} option for using stdin and stdout as the SMTP transport
  40. is unsupported and if it is passed to L{parseOptions}, L{SystemExit}
  41. is raised.
  42. """
  43. exc = self.assertRaises(SystemExit, parseOptions, ['-bs'])
  44. self.assertEqual(exc.args, ("Unsupported option.",))
  45. def test_ignoreFullStop(self):
  46. """
  47. The I{-i} and I{-oi} options for ignoring C{"."} by itself on a line
  48. are unsupported and if either is passed to L{parseOptions},
  49. L{SystemExit} is raised.
  50. """
  51. exc = self.assertRaises(SystemExit, parseOptions, ['-i'])
  52. self.assertEqual(exc.args, ("Unsupported option.",))
  53. exc = self.assertRaises(SystemExit, parseOptions, ['-oi'])
  54. self.assertEqual(exc.args, ("Unsupported option.",))
  55. def test_copyAliasedSender(self):
  56. """
  57. The I{-om} option for copying the sender if they appear in an alias
  58. expansion is unsupported and if it is passed to L{parseOptions},
  59. L{SystemExit} is raised.
  60. """
  61. exc = self.assertRaises(SystemExit, parseOptions, ['-om'])
  62. self.assertEqual(exc.args, ("Unsupported option.",))