summaryrefslogtreecommitdiff
path: root/Mailman/tests/test_handlers.py
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/tests/test_handlers.py')
-rw-r--r--Mailman/tests/test_handlers.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/Mailman/tests/test_handlers.py b/Mailman/tests/test_handlers.py
new file mode 100644
index 000000000..b8b33ba1a
--- /dev/null
+++ b/Mailman/tests/test_handlers.py
@@ -0,0 +1,119 @@
+# Copyright (C) 2001-2007 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
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""Unit tests for the various Mailman/Handlers/*.py modules."""
+
+import email
+import unittest
+
+from Mailman import Errors
+from Mailman import Message
+from Mailman import passwords
+from Mailman.MailList import MailList
+from Mailman.configuration import config
+from Mailman.tests.base import TestBase
+
+from Mailman.Handlers import Approve
+# Don't test handlers such as SMTPDirect and Sendmail here
+
+
+
+def password(cleartext):
+ return passwords.make_secret(cleartext, passwords.Schemes.ssha)
+
+
+
+class TestApprove(TestBase):
+ def test_short_circuit(self):
+ msgdata = {'approved': 1}
+ rtn = Approve.process(self._mlist, None, msgdata)
+ # Not really a great test, but there's little else to assert
+ self.assertEqual(rtn, None)
+
+ def test_approved_moderator(self):
+ mlist = self._mlist
+ mlist.mod_password = password('wazoo')
+ msg = email.message_from_string("""\
+Approved: wazoo
+
+""")
+ msgdata = {}
+ Approve.process(mlist, msg, msgdata)
+ self.failUnless(msgdata.has_key('approved'))
+ self.assertEqual(msgdata['approved'], 1)
+
+ def test_approve_moderator(self):
+ mlist = self._mlist
+ mlist.mod_password = password('wazoo')
+ msg = email.message_from_string("""\
+Approve: wazoo
+
+""")
+ msgdata = {}
+ Approve.process(mlist, msg, msgdata)
+ self.failUnless(msgdata.has_key('approved'))
+ self.assertEqual(msgdata['approved'], 1)
+
+ def test_approved_admin(self):
+ mlist = self._mlist
+ mlist.password = password('wazoo')
+ msg = email.message_from_string("""\
+Approved: wazoo
+
+""")
+ msgdata = {}
+ Approve.process(mlist, msg, msgdata)
+ self.failUnless(msgdata.has_key('approved'))
+ self.assertEqual(msgdata['approved'], 1)
+
+ def test_approve_admin(self):
+ mlist = self._mlist
+ mlist.password = password('wazoo')
+ msg = email.message_from_string("""\
+Approve: wazoo
+
+""")
+ msgdata = {}
+ Approve.process(mlist, msg, msgdata)
+ self.failUnless(msgdata.has_key('approved'))
+ self.assertEqual(msgdata['approved'], 1)
+
+ def test_unapproved(self):
+ mlist = self._mlist
+ mlist.password = password('zoowa')
+ msg = email.message_from_string("""\
+Approve: wazoo
+
+""")
+ msgdata = {}
+ Approve.process(mlist, msg, msgdata)
+ self.assertEqual(msgdata.get('approved'), None)
+
+ def test_trip_beentheres(self):
+ mlist = self._mlist
+ msg = email.message_from_string("""\
+X-BeenThere: %s
+
+""" % mlist.GetListEmail())
+ self.assertRaises(Errors.LoopError, Approve.process, mlist, msg, {})
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+## suite.addTest(unittest.makeSuite(TestApprove))
+ return suite