Abhilash's fix for allowing singleton strings in REST interfaces that also
[mailman.git] / src / mailman / rest / tests / test_validator.py
blobc670fc77c92bfbe22115c0c7e0f984e6f2dd8764
1 # Copyright (C) 2015 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Test REST validators."""
20 __all__ = [
21 'TestValidators',
25 import unittest
27 from mailman.rest.validator import list_of_strings_validator
28 from mailman.testing.layers import RESTLayer
32 class TestValidators(unittest.TestCase):
33 layer = RESTLayer
35 def test_list_of_strings_validator_single(self):
36 # This validator should turn a single key into a list of keys.
37 self.assertEqual(list_of_strings_validator('ant'), ['ant'])
39 def test_list_of_strings_validator_multiple(self):
40 # This validator should turn a single key into a list of keys.
41 self.assertEqual(
42 list_of_strings_validator(['ant', 'bee', 'cat']),
43 ['ant', 'bee', 'cat'])
45 def test_list_of_strings_validator_invalid(self):
46 # Strings are required.
47 self.assertRaises(ValueError, list_of_strings_validator, 7)
48 self.assertRaises(ValueError, list_of_strings_validator, ['ant', 7])