summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurkirpal2016-03-15 19:03:21 +0530
committerBarry Warsaw2016-03-22 09:39:03 -0400
commit75941917d8c57b41e2583079f22863326ebf9920 (patch)
tree15a80a4c1e0aebe5cc5342cc757b9156063da46b
parent472eb9765f4163aad785f483584ff607f01fdeeb (diff)
downloadmailman-75941917d8c57b41e2583079f22863326ebf9920.tar.gz
mailman-75941917d8c57b41e2583079f22863326ebf9920.tar.zst
mailman-75941917d8c57b41e2583079f22863326ebf9920.zip
-rw-r--r--src/mailman/commands/cli_lists.py15
-rw-r--r--src/mailman/commands/docs/create.rst11
-rw-r--r--src/mailman/commands/tests/test_create.py19
3 files changed, 39 insertions, 6 deletions
diff --git a/src/mailman/commands/cli_lists.py b/src/mailman/commands/cli_lists.py
index 830d84470..035dce898 100644
--- a/src/mailman/commands/cli_lists.py
+++ b/src/mailman/commands/cli_lists.py
@@ -153,11 +153,20 @@ class Create:
'-q', '--quiet',
default=False, action='store_true',
help=_('Print less output.'))
- command_parser.add_argument(
+ domain_options = command_parser.add_mutually_exclusive_group()
+ domain_options.add_argument(
'-d', '--domain',
- default=False, action='store_true',
+ default=True, action='store_true',
+ help=_("""\
+ Register the mailing list's domain if not yet registered."""),
+ dest='domain')
+ domain_options.add_argument(
+ '-D', '--no-domain',
+ default=False, action='store_false',
help=_("""\
- Register the mailing list's domain if not yet registered."""))
+ Do not register the mailing list's domain if not already registered."""),
+ dest='domain')
+
# Required positional argument.
command_parser.add_argument(
'listname', metavar='LISTNAME', nargs=1,
diff --git a/src/mailman/commands/docs/create.rst b/src/mailman/commands/docs/create.rst
index 1a5d2a3ab..aee6b1f05 100644
--- a/src/mailman/commands/docs/create.rst
+++ b/src/mailman/commands/docs/create.rst
@@ -33,6 +33,9 @@ domain. Both the mailing list and domain will be created.
>>> command.process(FakeArgs)
Created mailing list: test@example.xx
+This is the default behaviour. Even if you do not specify any option,
+Mailman will itself make the domain if it doesn't exist.
+
Now both the domain and the mailing list exist in the database.
::
@@ -46,8 +49,8 @@ Now both the domain and the mailing list exist in the database.
>>> getUtility(IDomainManager).get('example.xx')
<Domain example.xx, base_url: http://example.xx>
-You can also create mailing lists in existing domains without the
-auto-creation flag.
+You can also create mailing lists in existing domains by using the
+``-D`` or ``--no-domain`` flag.
::
>>> FakeArgs.domain = False
@@ -58,6 +61,10 @@ auto-creation flag.
>>> list_manager.get('test1@example.com')
<mailing list "test1@example.com" at ...>
+Although the ``--no-domain`` flag is not required when domain already
+exists it can be used to error out when domain doesn't exist. In such
+case, Mailman will give an error message.
+
The command can also operate quietly.
::
diff --git a/src/mailman/commands/tests/test_create.py b/src/mailman/commands/tests/test_create.py
index 67c58a13b..83a4dcb33 100644
--- a/src/mailman/commands/tests/test_create.py
+++ b/src/mailman/commands/tests/test_create.py
@@ -25,6 +25,7 @@ __all__ = [
import sys
import unittest
+from argparse import ArgumentParser
from mailman.app.lifecycle import create_list
from mailman.commands.cli_lists import Create
from mailman.testing.layers import ConfigLayer
@@ -55,7 +56,8 @@ class TestCreate(unittest.TestCase):
def setUp(self):
self.command = Create()
- self.command.parser = FakeParser()
+ self.parser = ArgumentParser()
+ self.command.add(FakeParser(), self.parser)
self.args = FakeArgs()
def test_cannot_create_duplicate_list(self):
@@ -90,3 +92,18 @@ class TestCreate(unittest.TestCase):
pass
self.assertEqual(self.command.parser.message,
'Illegal owner addresses: main=True')
+
+ def test_without_domain_option(self):
+ # Domain should be created if option not specified.
+ args = self.parser.parse_args('test@list.org'.split())
+ self.assertTrue(args.domain)
+
+ def test_with_domain_option(self):
+ # Domain should be created if option given.
+ args = self.parser.parse_args('-d test@list.org'.split())
+ self.assertTrue(args.domain)
+
+ def test_with_nodomain_option(self):
+ # Domain should not be created if --no-domain is given.
+ args = self.parser.parse_args('-D test@list.net'.split())
+ self.assertFalse(args.domain)