diff options
| author | Barry Warsaw | 2011-06-11 14:46:02 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2011-06-11 14:46:02 -0400 |
| commit | 2021d1cac5483cfe5bb356ce45914a820c64e0a2 (patch) | |
| tree | 1b0a0ce62780f2c701dc58acd76bc5b1392c7a14 /src | |
| parent | 2609d72b9968fe4d33f30249b88cc41e76feaf5a (diff) | |
| download | mailman-2021d1cac5483cfe5bb356ce45914a820c64e0a2.tar.gz mailman-2021d1cac5483cfe5bb356ce45914a820c64e0a2.tar.zst mailman-2021d1cac5483cfe5bb356ce45914a820c64e0a2.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/commands/cli_lists.py | 18 | ||||
| -rw-r--r-- | src/mailman/commands/docs/create.rst (renamed from src/mailman/commands/docs/create.txt) | 80 | ||||
| -rw-r--r-- | src/mailman/commands/tests/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/commands/tests/test_create.py | 93 |
4 files changed, 143 insertions, 48 deletions
diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py index 021ce5991..0b5973591 100644 --- a/src/mailman/commands/cli_lists.py +++ b/src/mailman/commands/cli_lists.py @@ -35,7 +35,8 @@ from mailman.config import config from mailman.core.constants import system_preferences from mailman.core.i18n import _ from mailman.email.message import UserNotification -from mailman.interfaces.address import InvalidEmailAddressError +from mailman.interfaces.address import ( + IEmailValidator, InvalidEmailAddressError) from mailman.interfaces.command import ICLISubCommand from mailman.interfaces.domain import ( BadDomainSpecificationError, IDomainManager) @@ -44,6 +45,9 @@ from mailman.interfaces.listmanager import IListManager, ListAlreadyExistsError from mailman.utilities.i18n import make +COMMASPACE = ', ' + + class Lists: """List all mailing lists""" @@ -186,6 +190,18 @@ class Create: domain_manager = getUtility(IDomainManager) if domain_manager.get(domain) is None and args.domain: domain_manager.add(domain) + # Validate the owner email addresses. The problem with doing this + # check in create_list() is that you wouldn't be able to distinguish + # between an InvalidEmailAddressError for the list name or the + # owners. I suppose we could subclass that exception though. + if args.owners: + validator = getUtility(IEmailValidator) + invalid_owners = (owner for owner in args.owners + if not validator.is_valid(owner)) + if invalid_owners: + invalid = COMMASPACE.join(sorted(invalid_owners)) + self.parser.error(_('Illegal owner addresses: $invalid')) + return try: mlist = create_list(fqdn_listname, args.owners) except InvalidEmailAddressError: diff --git a/src/mailman/commands/docs/create.txt b/src/mailman/commands/docs/create.rst index 31663a851..e902c58e1 100644 --- a/src/mailman/commands/docs/create.txt +++ b/src/mailman/commands/docs/create.rst @@ -11,9 +11,8 @@ A system administrator can create mailing lists by the command line. ... domain = None ... listname = None ... notify = False - >>> args = FakeArgs() -You cannot create a mailing list in an unknown domain... +You cannot create a mailing list in an unknown domain. >>> from mailman.commands.cli_lists import Create >>> command = Create() @@ -23,15 +22,15 @@ You cannot create a mailing list in an unknown domain... ... print message >>> command.parser = FakeParser() - >>> args.listname = ['test@example.xx'] - >>> command.process(args) + >>> FakeArgs.listname = ['test@example.xx'] + >>> command.process(FakeArgs) Undefined domain: example.xx -...although you can tell Mailman to auto-register the domain. In that case, -the mailing list and domain will be created. +The ``-d`` or ``--domain`` option is used to tell Mailman to auto-register the +domain. Both the mailing list and domain will be created. - >>> args.domain = True - >>> command.process(args) + >>> FakeArgs.domain = True + >>> command.process(FakeArgs) Created mailing list: test@example.xx Now both the domain and the mailing list exist in the database. @@ -52,9 +51,9 @@ You can also create mailing lists in existing domains without the auto-creation flag. :: - >>> args.domain = False - >>> args.listname = ['test1@example.com'] - >>> command.process(args) + >>> FakeArgs.domain = False + >>> FakeArgs.listname = ['test1@example.com'] + >>> command.process(FakeArgs) Created mailing list: test1@example.com >>> list_manager.get('test1@example.com') @@ -63,9 +62,9 @@ auto-creation flag. The command can also operate quietly. :: - >>> args.quiet = True - >>> args.listname = ['test2@example.com'] - >>> command.process(args) + >>> FakeArgs.quiet = True + >>> FakeArgs.listname = ['test2@example.com'] + >>> command.process(FakeArgs) >>> mlist = list_manager.get('test2@example.com') >>> mlist @@ -84,10 +83,10 @@ But you can specify an owner address on the command line when you create the mailing list. :: - >>> args.quiet = False - >>> args.listname = ['test4@example.com'] - >>> args.owners = ['foo@example.org'] - >>> command.process(args) + >>> FakeArgs.quiet = False + >>> FakeArgs.listname = ['test4@example.com'] + >>> FakeArgs.owners = ['foo@example.org'] + >>> command.process(FakeArgs) Created mailing list: test4@example.com >>> mlist = list_manager.get('test4@example.com') @@ -97,9 +96,11 @@ mailing list. You can even specify more than one address for the owners. :: - >>> args.owners = ['foo@example.net', 'bar@example.net', 'baz@example.net'] - >>> args.listname = ['test5@example.com'] - >>> command.process(args) + >>> FakeArgs.owners = ['foo@example.net', + ... 'bar@example.net', + ... 'baz@example.net'] + >>> FakeArgs.listname = ['test5@example.com'] + >>> command.process(FakeArgs) Created mailing list: test5@example.com >>> mlist = list_manager.get('test5@example.com') @@ -117,24 +118,24 @@ You can set the default language for the new mailing list when you create it. The language must be known to Mailman. :: - >>> args.listname = ['test3@example.com'] - >>> args.language = 'ee' - >>> command.process(args) + >>> FakeArgs.listname = ['test3@example.com'] + >>> FakeArgs.language = 'ee' + >>> command.process(FakeArgs) Invalid language code: ee >>> from mailman.interfaces.languages import ILanguageManager >>> getUtility(ILanguageManager).add('ee', 'iso-8859-1', 'Freedonian') - >>> args.quiet = False - >>> args.listname = ['test3@example.com'] - >>> args.language = 'fr' - >>> command.process(args) + >>> FakeArgs.quiet = False + >>> FakeArgs.listname = ['test3@example.com'] + >>> FakeArgs.language = 'fr' + >>> command.process(FakeArgs) Created mailing list: test3@example.com >>> mlist = list_manager.get('test3@example.com') >>> print mlist.preferred_language <Language [fr] French> - >>> args.language = None + >>> FakeArgs.language = None Notifications @@ -142,9 +143,9 @@ Notifications When told to, Mailman will notify the list owners of their new mailing list. - >>> args.listname = ['test6@example.com'] - >>> args.notify = True - >>> command.process(args) + >>> FakeArgs.listname = ['test6@example.com'] + >>> FakeArgs.notify = True + >>> command.process(FakeArgs) Created mailing list: test6@example.com The notification message is in the virgin queue. @@ -183,18 +184,3 @@ The notification message is in the virgin queue. <BLANKLINE> Please address all questions to noreply@example.com. <BLANKLINE> - - -Errors -====== - -You cannot create a mailing list that already exists. - - >>> command.process(args) - List already exists: test6@example.com - -The posting address of the mailing list must be valid. - - >>> args.listname = ['foo'] - >>> command.process(args) - Illegal list name: foo diff --git a/src/mailman/commands/tests/__init__.py b/src/mailman/commands/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/commands/tests/__init__.py diff --git a/src/mailman/commands/tests/test_create.py b/src/mailman/commands/tests/test_create.py new file mode 100644 index 000000000..c2176a106 --- /dev/null +++ b/src/mailman/commands/tests/test_create.py @@ -0,0 +1,93 @@ +# Copyright (C) 2011 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 `bin/mailman create`.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'test_suite', + ] + + +import unittest + +from mailman.app.lifecycle import create_list +from mailman.commands.cli_lists import Create +from mailman.testing.layers import ConfigLayer + + + +class FakeArgs: + language = None + owners = [] + quiet = False + domain = None + listname = None + notify = False + + +class FakeParser: + def __init__(self): + self.message = None + + def error(self, message): + self.message = message + + + +class TestCreate(unittest.TestCase): + """Test `bin/mailman create`.""" + + layer = ConfigLayer + + def setUp(self): + self.command = Create() + self.command.parser = FakeParser() + self.args = FakeArgs() + + def test_cannot_create_duplicate_list(self): + # Cannot create a mailing list if it already exists. + create_list('test@example.com') + self.args.listname = ['test@example.com'] + self.command.process(self.args) + self.assertEqual(self.command.parser.message, + 'List already exists: test@example.com') + + def test_invalid_posting_address(self): + # Cannot create a mailing list with an invalid posting address. + self.args.listname = ['foo'] + self.command.process(self.args) + self.assertEqual(self.command.parser.message, + 'Illegal list name: foo') + + def test_invalid_owner_addresses(self): + # Cannot create a list with invalid owner addresses. LP: #778687 + self.args.listname = ['test@example.com'] + self.args.domain = True + self.args.owners = ['main=True'] + self.command.process(self.args) + self.assertEqual(self.command.parser.message, + 'Illegal owner addresses: main=True') + + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestCreate)) + return suite |
