1# Copyright (C) 2003-2018 by the Free Software Foundation, Inc. 2# 3# This program is free software; you can redistribute it and/or 4# modify it under the terms of the GNU General Public License 5# as published by the Free Software Foundation; either version 2 6# of the License, or (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 17"""Unit tests for SMTPDirect and (eventually perhaps) Sendmail. 18""" 19 20import email 21import unittest 22import thread 23try: 24 from Mailman import __init__ 25except ImportError: 26 import paths 27 28from Mailman import mm_cfg 29from Mailman.Handlers import SMTPDirect 30 31from EmailBase import EmailBase 32 33TESTPORT = 3925 34 35 36 37class TestSMTPDirect(EmailBase): 38 def setUp(self): 39 self._origport = mm_cfg.SMTPPORT 40 self._sessions = mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION 41 mm_cfg.SMTPPORT = TESTPORT 42 mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION = 1 43 EmailBase.setUp(self) 44 45 def tearDown(self): 46 mm_cfg.SMTPPORT = self._origport 47 mm_cfg.SMTP_MAX_SESSIONS_PER_CONNECTION = self._sessions 48 EmailBase.tearDown(self) 49 50 def test_disconnect_midsession(self): 51 msgdata = {'recips': ['aperson@dom.ain', 'bperson@dom.ain'], 52 'personalize': 1, 53 } 54 self._mlist.personalize = 1 55 msg = email.message_from_string(""" 56From: cperson@dom.ain 57To: _xtest@dom.ain 58Subject: testing 59 60testing 61""") 62 id = thread.start_new_thread(self._readmsg, ()) 63 SMTPDirect.process(self._mlist, msg, msgdata) 64 65 66 67def suite(): 68 suite = unittest.TestSuite() 69 #suite.addTest(unittest.makeSuite(TestSMTPDirect)) 70 return suite 71 72 73if __name__ == '__main__': 74 unittest.main(defaultTest='suite') 75