diff options
author | Mark Sapiro <mark@msapiro.net> | 2010-07-11 10:03:44 -0700 |
---|---|---|
committer | Mark Sapiro <mark@msapiro.net> | 2010-07-11 10:03:44 -0700 |
commit | 6786292e5070a26e4112625899147d6a56c8f407 (patch) | |
tree | 07b2c7853513d96ab186f4b7b12cec6ac96688b0 | |
parent | 4d267c2af1c4703b6d8e9daa690bd06037c4d89e (diff) | |
download | mailman2-6786292e5070a26e4112625899147d6a56c8f407.tar.gz mailman2-6786292e5070a26e4112625899147d6a56c8f407.tar.xz mailman2-6786292e5070a26e4112625899147d6a56c8f407.zip |
Updated unit tests for current Mailman so all tests should pass.
Diffstat (limited to '')
-rw-r--r-- | tests/EmailBase.py | 4 | ||||
-rw-r--r-- | tests/test_bounces.py | 6 | ||||
-rw-r--r-- | tests/test_handlers.py | 33 | ||||
-rw-r--r-- | tests/test_lockfile.py | 6 | ||||
-rw-r--r-- | tests/test_membership.py | 7 | ||||
-rw-r--r-- | tests/test_message.py | 50 | ||||
-rw-r--r-- | tests/test_runners.py | 6 | ||||
-rw-r--r-- | tests/test_safedict.py | 6 | ||||
-rw-r--r-- | tests/test_security_mgr.py | 16 | ||||
-rw-r--r-- | tests/test_smtp.py | 6 |
10 files changed, 97 insertions, 43 deletions
diff --git a/tests/EmailBase.py b/tests/EmailBase.py index d83ccbcf..69868c82 100644 --- a/tests/EmailBase.py +++ b/tests/EmailBase.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2003 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -49,6 +49,8 @@ class SinkServer(smtpd.SMTPServer): class EmailBase(TestBase): def setUp(self): TestBase.setUp(self) + if mm_cfg.SMTPPORT == 0: + mm_cfg.SMTPPORT = 25 # Second argument tuple is ignored. self._server = SinkServer(('localhost', mm_cfg.SMTPPORT), ('localhost', 25)) diff --git a/tests/test_bounces.py b/tests/test_bounces.py index 9a4cba4d..e3b07da0 100644 --- a/tests/test_bounces.py +++ b/tests/test_bounces.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2009 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -21,6 +21,10 @@ import sys import os import unittest import email +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman.Bouncers.BouncerAPI import Stop diff --git a/tests/test_handlers.py b/tests/test_handlers.py index 7b053c65..ef9a30ec 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2008 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -26,6 +26,10 @@ import cPickle import unittest from types import ListType from email.Generator import Generator +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import mm_cfg from Mailman.MailList import MailList @@ -208,7 +212,7 @@ class TestAfterDelivery(TestBase): class TestApprove(TestBase): def test_short_circuit(self): msgdata = {'approved': 1} - rtn = Approve.process(self._mlist, None, msgdata) + rtn = Approve.process(self._mlist, Message.Message(), msgdata) # Not really a great test, but there's little else to assert self.assertEqual(rtn, None) @@ -549,7 +553,7 @@ Subject: About Mailman... """, Message.Message) CookHeaders.process(self._mlist, msg, {}) - self.assertEqual(msg['subject'], '[XTEST] About Mailman...') + self.assertEqual(str(msg['subject']), '[XTEST] About Mailman...') def test_no_subject_munging_for_digests(self): self._mlist.subject_prefix = '[XTEST] ' @@ -579,7 +583,9 @@ Subject: Re: [XTEST] About Mailman... """, Message.Message) CookHeaders.process(self._mlist, msg, {}) - self.assertEqual(msg['subject'], 'Re: [XTEST] About Mailman...') + # prefixing depends on mm_cfg.py + self.failUnless(str(msg['subject']) == 'Re: [XTEST] About Mailman...' or + str(msg['subject']) == '[XTEST] Re: About Mailman...') def test_reply_to_list(self): eq = self.assertEqual @@ -692,7 +698,7 @@ From: aperson@dom.ain eq(msg['list-id'], '<_xtest.dom.ain>') eq(msg['list-help'], '<mailto:_xtest-request@dom.ain?subject=help>') eq(msg['list-unsubscribe'], - '<http://www.dom.ain/mailman/listinfo/_xtest>,' + '<http://www.dom.ain/mailman/options/_xtest>,' '\n\t<mailto:_xtest-request@dom.ain?subject=unsubscribe>') eq(msg['list-subscribe'], '<http://www.dom.ain/mailman/listinfo/_xtest>,' @@ -709,10 +715,10 @@ From: aperson@dom.ain """, Message.Message) CookHeaders.process(self._mlist, msg, {}) - eq(msg['list-id'].__unicode__(), 'A Test List <_xtest.dom.ain>') + eq(unicode(msg['list-id']), 'A Test List <_xtest.dom.ain>') eq(msg['list-help'], '<mailto:_xtest-request@dom.ain?subject=help>') eq(msg['list-unsubscribe'], - '<http://www.dom.ain/mailman/listinfo/_xtest>,' + '<http://www.dom.ain/mailman/options/_xtest>,' '\n\t<mailto:_xtest-request@dom.ain?subject=unsubscribe>') eq(msg['list-subscribe'], '<http://www.dom.ain/mailman/listinfo/_xtest>,' @@ -1115,7 +1121,7 @@ From: aperson@dom.ain cookie = confirmlines[-3].split('/')[-1] # We also need to make sure there's an entry in the Pending database # for the heold message. - data = Pending.confirm(cookie) + data = self._mlist.pend_confirm(cookie) eq(data, ('H', 1)) heldmsg = os.path.join(mm_cfg.DATA_DIR, 'heldmsg-_xtest-1.pck') self.failUnless(os.path.exists(heldmsg)) @@ -1499,7 +1505,8 @@ It rocks! files = self._sb.files() eq(len(files), 1) msg2, data = self._sb.dequeue(files[0]) - eq(len(data), 2) + eq(len(data), 3) + eq(data['_parsemsg'], False) eq(data['version'], 3) # Clock skew makes this unreliable #self.failUnless(data['received_time'] <= time.time()) @@ -1567,7 +1574,7 @@ Here is message %(i)d # is the RFC 1153 digest. for filebase in files: qmsg, qdata = self._sb.dequeue(filebase) - if qmsg.get_main_type() == 'multipart': + if qmsg.get_content_maintype() == 'multipart': mimemsg = qmsg mimedata = qdata else: @@ -1611,12 +1618,14 @@ It rocks! eq(len(files), 1) msg2, data = self._sb.dequeue(files[0]) eq(msg.as_string(unixfrom=0), msg2.as_string(unixfrom=0)) - eq(len(data), 6) + self.failUnless(len(data) >= 6 and len(data) <= 7) eq(data['foo'], 1) eq(data['bar'], 2) eq(data['version'], 3) eq(data['listname'], '_xtest') - eq(data['verp'], 1) + eq(data['_parsemsg'], False) + # Can't test verp. presence/value depend on mm_cfg.py + #eq(data['verp'], 1) # Clock skew makes this unreliable #self.failUnless(data['received_time'] <= time.time()) diff --git a/tests/test_lockfile.py b/tests/test_lockfile.py index 832e745f..4a7cf41e 100644 --- a/tests/test_lockfile.py +++ b/tests/test_lockfile.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002 by the Free Software Foundation, Inc. +# Copyright (C) 2002-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,6 +18,10 @@ """ import unittest +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman.LockFile import LockFile diff --git a/tests/test_membership.py b/tests/test_membership.py index 8ffda18b..eca57862 100644 --- a/tests/test_membership.py +++ b/tests/test_membership.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2003 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -20,6 +20,10 @@ import os import time import unittest +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import mm_cfg from Mailman import Utils @@ -196,6 +200,7 @@ class TestMembers(TestBase): def test_set_language(self): self._mlist.available_languages.append('xx') + mm_cfg.LC_DESCRIPTIONS.setdefault('xx', 0) self._mlist.setMemberLanguage('person@dom.ain', 'xx') self.assertEqual(self._mlist.getMemberLanguage('person@dom.ain'), 'xx') diff --git a/tests/test_message.py b/tests/test_message.py index 6a4cc3d2..00f524f4 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2008 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,8 +17,13 @@ """Unit tests for the various Message class methods. """ +import sys import unittest import email +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import Message from Mailman import Version @@ -28,7 +33,7 @@ from EmailBase import EmailBase -class TestSentMessage(EmailBase): +class TestSentMessage1(EmailBase): def test_user_notification(self): eq = self.assertEqual unless = self.failUnless @@ -46,23 +51,16 @@ class TestSentMessage(EmailBase): msgid = qmsg['message-id'] unless(msgid.startswith('<mailman.')) unless(msgid.endswith('._xtest@dom.ain>')) - eq(qmsg['sender'], '_xtest-admin@dom.ain') - eq(qmsg['errors-to'], '_xtest-admin@dom.ain') + eq(qmsg['sender'], '_xtest-bounces@dom.ain') + eq(qmsg['errors-to'], '_xtest-bounces@dom.ain') eq(qmsg['x-beenthere'], '_xtest@dom.ain') eq(qmsg['x-mailman-version'], Version.VERSION) eq(qmsg['precedence'], 'bulk') - eq(qmsg['list-help'], '<mailto:_xtest-request@dom.ain?subject=help>') - eq(qmsg['list-post'], '<mailto:_xtest@dom.ain>') - eq(qmsg['list-subscribe'], """\ -<http://www.dom.ain/mailman/listinfo/_xtest>, - <mailto:_xtest-request@dom.ain?subject=subscribe>""") eq(qmsg['list-id'], '<_xtest.dom.ain>') - eq(qmsg['list-unsubscribe'], """\ -<http://www.dom.ain/mailman/listinfo/_xtest>, - <mailto:_xtest-request@dom.ain?subject=unsubscribe>""") - eq(qmsg['list-archive'], '<http://www.dom.ain/pipermail/_xtest>') + eq(qmsg['x-list-administrivia'], 'yes') eq(qmsg.get_payload(), 'About your test list') +class TestSentMessage2(EmailBase): def test_bounce_message(self): eq = self.assertEqual unless = self.failUnless @@ -82,21 +80,35 @@ yadda yadda yadda # message. msg1 = qmsg.get_payload(0) eq(msg1.get_content_type(), 'text/plain') - eq(msg1.get_payload(), '[No bounce details are available]\n') + eq(msg1.get_payload(), '[No bounce details are available]') msg2 = qmsg.get_payload(1) eq(msg2.get_content_type(), 'message/rfc822') - unless(not msg2.is_multipart()) - msg3 = msg2.get_payload() + unless(msg2.is_multipart()) + msg3 = msg2.get_payload(0) eq(msg3.get_payload(), 'yadda yadda yadda\n') -def suite(): +def suite(x): suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestSentMessage)) + if x == '1': + suite.addTest(unittest.makeSuite(TestSentMessage1)) + elif x == '2': + suite.addTest(unittest.makeSuite(TestSentMessage2)) return suite if __name__ == '__main__': - unittest.main(defaultTest='suite') + # There is some issue in asyncore.py that prevents successfully running more than + # one test at a time, so specify which of the two tests as an argument. + if len(sys.argv) == 1: + x = '1' + else: + x = sys.argv[1] + if x not in ('1', '2'): + print >> sys.stderr, ( + 'usage: python test_message.py [n] where n = 1, 2 is the sub-test to run.') + sys.exit(1) + unittest.TextTestRunner(verbosity=2).run(suite(x)) + diff --git a/tests/test_runners.py b/tests/test_runners.py index c0baf02b..a0613b33 100644 --- a/tests/test_runners.py +++ b/tests/test_runners.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -19,6 +19,10 @@ import unittest import email +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman.Queue.NewsRunner import prepare_message diff --git a/tests/test_safedict.py b/tests/test_safedict.py index 27d6adb3..bf8dd921 100644 --- a/tests/test_safedict.py +++ b/tests/test_safedict.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -19,6 +19,10 @@ import email import unittest +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import SafeDict diff --git a/tests/test_security_mgr.py b/tests/test_security_mgr.py index e829d0c9..425a472b 100644 --- a/tests/test_security_mgr.py +++ b/tests/test_security_mgr.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2008 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -28,6 +28,10 @@ except ImportError: crypt = None # Don't use cStringIO because we're going to inherit from StringIO import StringIO +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import mm_cfg from Mailman import Utils @@ -171,14 +175,16 @@ class TestAuthenticate(TestBase): def test_wrong_user(self): mlist = self._mlist mlist.addNewMember('aperson@dom.ain', password='nosrepa') - self.assertRaises(Errors.NotAMemberError, mlist.Authenticate, - [mm_cfg.AuthUser], 'nosrepa', 'bperson@dom.ain') + self.assertEqual(mlist.Authenticate( + [mm_cfg.AuthUser], 'nosrepa', 'bperson@dom.ain'), + mm_cfg.UnAuthorized) def test_no_user(self): mlist = self._mlist mlist.addNewMember('aperson@dom.ain', password='nosrepa') - self.assertRaises(AttributeError, mlist.Authenticate, - [mm_cfg.AuthUser], 'nosrepa') + self.assertEqual(mlist.Authenticate( + [mm_cfg.AuthUser], 'nosrepa'), + mm_cfg.UnAuthorized) def test_user_unauth(self): mlist = self._mlist diff --git a/tests/test_smtp.py b/tests/test_smtp.py index e9fc49b8..857f968c 100644 --- a/tests/test_smtp.py +++ b/tests/test_smtp.py @@ -1,4 +1,4 @@ -# Copyright (C) 2003 by the Free Software Foundation, Inc. +# Copyright (C) 2003-2010 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -20,6 +20,10 @@ import email import unittest import thread +try: + from Mailman import __init__ +except ImportError: + import paths from Mailman import mm_cfg from Mailman.Handlers import SMTPDirect |