summaryrefslogtreecommitdiff
path: root/src/mailman/rest/tests/test_validator.py
diff options
context:
space:
mode:
authorBarry Warsaw2015-04-15 10:43:56 -0400
committerBarry Warsaw2015-04-15 10:43:56 -0400
commit21b6943debd12275a618301340508e2ba827a9c4 (patch)
tree04c4ba70bde5213616fc8f7a3b78d0dc904fe58d /src/mailman/rest/tests/test_validator.py
parent67fd8d6dbcf8849b3c2f8cb42a10aed465ace76c (diff)
parentcfbffa2ac1c5b6743705d3cc39d663eb642e7184 (diff)
downloadmailman-21b6943debd12275a618301340508e2ba827a9c4.tar.gz
mailman-21b6943debd12275a618301340508e2ba827a9c4.tar.zst
mailman-21b6943debd12275a618301340508e2ba827a9c4.zip
Diffstat (limited to 'src/mailman/rest/tests/test_validator.py')
-rw-r--r--src/mailman/rest/tests/test_validator.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/mailman/rest/tests/test_validator.py b/src/mailman/rest/tests/test_validator.py
new file mode 100644
index 000000000..c670fc77c
--- /dev/null
+++ b/src/mailman/rest/tests/test_validator.py
@@ -0,0 +1,48 @@
+# Copyright (C) 2015 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test REST validators."""
+
+__all__ = [
+ 'TestValidators',
+ ]
+
+
+import unittest
+
+from mailman.rest.validator import list_of_strings_validator
+from mailman.testing.layers import RESTLayer
+
+
+
+class TestValidators(unittest.TestCase):
+ layer = RESTLayer
+
+ def test_list_of_strings_validator_single(self):
+ # This validator should turn a single key into a list of keys.
+ self.assertEqual(list_of_strings_validator('ant'), ['ant'])
+
+ def test_list_of_strings_validator_multiple(self):
+ # This validator should turn a single key into a list of keys.
+ self.assertEqual(
+ list_of_strings_validator(['ant', 'bee', 'cat']),
+ ['ant', 'bee', 'cat'])
+
+ def test_list_of_strings_validator_invalid(self):
+ # Strings are required.
+ self.assertRaises(ValueError, list_of_strings_validator, 7)
+ self.assertRaises(ValueError, list_of_strings_validator, ['ant', 7])