summaryrefslogtreecommitdiff
path: root/Mailman/testing
diff options
context:
space:
mode:
Diffstat (limited to 'Mailman/testing')
-rw-r--r--Mailman/testing/test_enum.py117
-rw-r--r--Mailman/testing/test_passwords.py129
2 files changed, 246 insertions, 0 deletions
diff --git a/Mailman/testing/test_enum.py b/Mailman/testing/test_enum.py
new file mode 100644
index 000000000..6f198df67
--- /dev/null
+++ b/Mailman/testing/test_enum.py
@@ -0,0 +1,117 @@
+# Copyright (C) 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 Enums."""
+
+import operator
+import unittest
+
+from Mailman.enum import Enum
+
+
+
+class Colors(Enum):
+ red = 1
+ green = 2
+ blue = 3
+
+
+class MoreColors(Colors):
+ pink = 4
+ cyan = 5
+
+
+class OtherColors(Enum):
+ red = 1
+ blue = 2
+ yellow = 3
+
+
+
+class TestEnum(unittest.TestCase):
+ def test_enum_basics(self):
+ unless = self.failUnless
+ raises = self.assertRaises
+ # Cannot compare by equality
+ raises(NotImplementedError, operator.eq, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.ne, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.lt, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.gt, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.le, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.ge, Colors.red, Colors.red)
+ raises(NotImplementedError, operator.eq, Colors.red, 1)
+ raises(NotImplementedError, operator.ne, Colors.red, 1)
+ raises(NotImplementedError, operator.lt, Colors.red, 1)
+ raises(NotImplementedError, operator.gt, Colors.red, 1)
+ raises(NotImplementedError, operator.le, Colors.red, 1)
+ raises(NotImplementedError, operator.ge, Colors.red, 1)
+ # Comparison by identity
+ unless(Colors.red is Colors.red)
+ unless(Colors.red is MoreColors.red)
+ unless(Colors.red is not OtherColors.red)
+ unless(Colors.red is not Colors.blue)
+
+ def test_enum_conversions(self):
+ eq = self.assertEqual
+ unless = self.failUnless
+ raises = self.assertRaises
+ unless(Colors.red is Colors['red'])
+ unless(Colors.red is Colors[1])
+ unless(Colors.red is Colors('red'))
+ unless(Colors.red is Colors(1))
+ unless(Colors.red is not Colors['blue'])
+ unless(Colors.red is not Colors[2])
+ unless(Colors.red is not Colors('blue'))
+ unless(Colors.red is not Colors(2))
+ unless(Colors.red is MoreColors['red'])
+ unless(Colors.red is MoreColors[1])
+ unless(Colors.red is MoreColors('red'))
+ unless(Colors.red is MoreColors(1))
+ unless(Colors.red is not OtherColors['red'])
+ unless(Colors.red is not OtherColors[1])
+ unless(Colors.red is not OtherColors('red'))
+ unless(Colors.red is not OtherColors(1))
+ raises(ValueError, Colors.__getitem__, 'magenta')
+ raises(ValueError, Colors.__getitem__, 99)
+ raises(ValueError, Colors.__call__, 'magenta')
+ raises(ValueError, Colors.__call__, 99)
+ eq(int(Colors.red), 1)
+ eq(int(Colors.blue), 3)
+ eq(int(MoreColors.red), 1)
+ eq(int(OtherColors.blue), 2)
+
+
+ def test_enum_duplicates(self):
+ try:
+ class Bad(Enum):
+ cartman = 1
+ stan = 2
+ kyle = 3
+ kenny = 3
+ butters = 4
+ except TypeError:
+ got_error = True
+ else:
+ got_error = False
+ self.failUnless(got_error)
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestEnum))
+ return suite
diff --git a/Mailman/testing/test_passwords.py b/Mailman/testing/test_passwords.py
new file mode 100644
index 000000000..1d4899f8f
--- /dev/null
+++ b/Mailman/testing/test_passwords.py
@@ -0,0 +1,129 @@
+# Copyright (C) 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 passwords module."""
+
+import unittest
+
+from Mailman import passwords
+
+
+
+class TestPasswordsBase(unittest.TestCase):
+ scheme = None
+
+ def setUp(self):
+ # passwords; 8-bit or unicode strings; ascii or binary
+ self.pw8a = 'abc'
+ self.pwua = u'abc'
+ self.pw8b = 'abc\xc3\xbf' # 'abc\xff'
+ self.pwub = u'abc\xff'
+ # bad password; 8-bit or unicode; ascii or binary
+ self.bad8a = 'xyz'
+ self.badua = u'xyz'
+ self.bad8b = 'xyz\xc3\xbf' # 'xyz\xff'
+ self.badub = u'xyz\xff'
+
+ def test_passwords(self):
+ unless = self.failUnless
+ failif = self.failIf
+ secret = passwords.make_secret(self.pw8a, self.scheme)
+ unless(passwords.check_response(secret, self.pw8a))
+ failif(passwords.check_response(secret, self.bad8a))
+
+ def test_unicode_passwords(self):
+ unless = self.failUnless
+ failif = self.failIf
+ secret = passwords.make_secret(self.pwua, self.scheme)
+ unless(passwords.check_response(secret, self.pwua))
+ failif(passwords.check_response(secret, self.badua))
+
+ def test_passwords_with_funky_chars(self):
+ unless = self.failUnless
+ failif = self.failIf
+ secret = passwords.make_secret(self.pw8b, self.scheme)
+ unless(passwords.check_response(secret, self.pw8b))
+ failif(passwords.check_response(secret, self.bad8b))
+
+ def test_unicode_passwords_with_funky_chars(self):
+ unless = self.failUnless
+ failif = self.failIf
+ secret = passwords.make_secret(self.pwub, self.scheme)
+ unless(passwords.check_response(secret, self.pwub))
+ failif(passwords.check_response(secret, self.badub))
+
+
+
+class TestBogusPasswords(TestPasswordsBase):
+ scheme = -1
+
+ def test_passwords(self):
+ failif = self.failIf
+ secret = passwords.make_secret(self.pw8a, self.scheme)
+ failif(passwords.check_response(secret, self.pw8a))
+ failif(passwords.check_response(secret, self.bad8a))
+
+ def test_unicode_passwords(self):
+ failif = self.failIf
+ secret = passwords.make_secret(self.pwua, self.scheme)
+ failif(passwords.check_response(secret, self.pwua))
+ failif(passwords.check_response(secret, self.badua))
+
+ def test_passwords_with_funky_chars(self):
+ failif = self.failIf
+ secret = passwords.make_secret(self.pw8b, self.scheme)
+ failif(passwords.check_response(secret, self.pw8b))
+ failif(passwords.check_response(secret, self.bad8b))
+
+ def test_unicode_passwords_with_funky_chars(self):
+ failif = self.failIf
+ secret = passwords.make_secret(self.pwub, self.scheme)
+ failif(passwords.check_response(secret, self.pwub))
+ failif(passwords.check_response(secret, self.badub))
+
+
+
+class TestNonePasswords(TestBogusPasswords):
+ scheme = passwords.Schemes.no_scheme
+
+
+class TestCleartextPasswords(TestPasswordsBase):
+ scheme = passwords.Schemes.cleartext
+
+
+class TestSHAPasswords(TestPasswordsBase):
+ scheme = passwords.Schemes.sha
+
+
+class TestSSHAPasswords(TestPasswordsBase):
+ scheme = passwords.Schemes.ssha
+
+
+class TestPBKDF2Passwords(TestPasswordsBase):
+ scheme = passwords.Schemes.pbkdf2
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestBogusPasswords))
+ suite.addTest(unittest.makeSuite(TestNonePasswords))
+ suite.addTest(unittest.makeSuite(TestCleartextPasswords))
+ suite.addTest(unittest.makeSuite(TestSHAPasswords))
+ suite.addTest(unittest.makeSuite(TestSSHAPasswords))
+ suite.addTest(unittest.makeSuite(TestPBKDF2Passwords))
+ return suite