diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/interfaces/domain.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_domains.py | 17 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_validator.py | 48 | ||||
| -rw-r--r-- | src/mailman/rest/validator.py | 4 |
4 files changed, 69 insertions, 2 deletions
diff --git a/src/mailman/interfaces/domain.py b/src/mailman/interfaces/domain.py index 33d835325..d5cbf8e2b 100644 --- a/src/mailman/interfaces/domain.py +++ b/src/mailman/interfaces/domain.py @@ -89,7 +89,7 @@ class IDomain(Interface): 'The human readable description of the domain name.') owners = Attribute("""\ - The relationship with the user database representing domain owners""") + The relationship with the user database representing domain owners.""") mailing_lists = Attribute( """All mailing lists for this domain. diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py index 716ded580..9d03859ef 100644 --- a/src/mailman/rest/tests/test_domains.py +++ b/src/mailman/rest/tests/test_domains.py @@ -27,6 +27,7 @@ import unittest from mailman.app.lifecycle import create_list from mailman.database.transaction import transaction +from mailman.interfaces.domain import IDomainManager from mailman.interfaces.listmanager import IListManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -54,6 +55,21 @@ class TestDomains(unittest.TestCase): 'http://localhost:9001/3.0/domains', data, method="POST") self.assertEqual(response.status, 201) + def test_domain_create_with_single_owner(self): + # Creating domain with single owner should not raise InvalidEmailError. + content, response = call_api( + 'http://localhost:9001/3.0/domains', dict( + mail_host='example.net', + owner='anne@example.com', + ), + method='POST') + self.assertEqual(response.status, 201) + # The domain has the expected owner. + domain = getUtility(IDomainManager).get('example.net') + self.assertEqual( + [list(owner.addresses)[0].email for owner in domain.owners], + ['anne@example.com']) + def test_bogus_endpoint_extension(self): # /domains/<domain>/lists/<anything> is not a valid endpoint. with self.assertRaises(HTTPError) as cm: @@ -102,6 +118,7 @@ class TestDomains(unittest.TestCase): self.assertEqual(cm.exception.code, 404) + class TestDomainOwners(unittest.TestCase): layer = RESTLayer 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]) diff --git a/src/mailman/rest/validator.py b/src/mailman/rest/validator.py index d09886e36..720d7adc1 100644 --- a/src/mailman/rest/validator.py +++ b/src/mailman/rest/validator.py @@ -68,7 +68,9 @@ def language_validator(code): def list_of_strings_validator(values): - """Turn a list of things into a list of unicodes.""" + """Turn a list of things, or a single thing, into a list of unicodes.""" + if not isinstance(values, (list, tuple)): + values = [values] for value in values: if not isinstance(value, str): raise ValueError('Expected str, got {!r}'.format(value)) |
