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