summaryrefslogtreecommitdiff
path: root/src/mailman/commands/tests
diff options
context:
space:
mode:
authorBarry Warsaw2016-03-24 15:12:45 -0400
committerBarry Warsaw2016-03-24 15:12:45 -0400
commitd964be9f9a141772bb0538f7bc7ecfbf83950a02 (patch)
treeac64133d73352829e5d58deb3f7553098ae12f4b /src/mailman/commands/tests
parent8cc7e77b85f013d6f9ea4cda16ae18856fd6ccee (diff)
downloadmailman-d964be9f9a141772bb0538f7bc7ecfbf83950a02.tar.gz
mailman-d964be9f9a141772bb0538f7bc7ecfbf83950a02.tar.zst
mailman-d964be9f9a141772bb0538f7bc7ecfbf83950a02.zip
Clean up the commands subdirectory.
Diffstat (limited to 'src/mailman/commands/tests')
-rw-r--r--src/mailman/commands/tests/test_conf.py7
-rw-r--r--src/mailman/commands/tests/test_confirm.py25
-rw-r--r--src/mailman/commands/tests/test_control.py26
-rw-r--r--src/mailman/commands/tests/test_create.py20
-rw-r--r--src/mailman/commands/tests/test_digests.py57
-rw-r--r--src/mailman/commands/tests/test_help.py6
-rw-r--r--src/mailman/commands/tests/test_import.py7
-rw-r--r--src/mailman/commands/tests/test_lists.py5
-rw-r--r--src/mailman/commands/tests/test_members.py7
9 files changed, 33 insertions, 127 deletions
diff --git a/src/mailman/commands/tests/test_conf.py b/src/mailman/commands/tests/test_conf.py
index 2fae55f17..745d4bda3 100644
--- a/src/mailman/commands/tests/test_conf.py
+++ b/src/mailman/commands/tests/test_conf.py
@@ -17,11 +17,6 @@
"""Test the conf subcommand."""
-__all__ = [
- 'TestConf',
- ]
-
-
import os
import sys
import tempfile
@@ -33,7 +28,6 @@ from mailman.testing.layers import ConfigLayer
from unittest import mock
-
class FakeArgs:
section = None
key = None
@@ -50,7 +44,6 @@ class FakeParser:
sys.exit(1)
-
class TestConf(unittest.TestCase):
"""Test the conf subcommand."""
diff --git a/src/mailman/commands/tests/test_confirm.py b/src/mailman/commands/tests/test_confirm.py
index 5f62331c0..7cce4c3c7 100644
--- a/src/mailman/commands/tests/test_confirm.py
+++ b/src/mailman/commands/tests/test_confirm.py
@@ -17,12 +17,6 @@
"""Test the `confirm` command."""
-__all__ = [
- 'TestConfirm',
- 'TestEmailResponses',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -39,7 +33,6 @@ from mailman.testing.layers import ConfigLayer
from zope.component import getUtility
-
class TestConfirm(unittest.TestCase):
"""Test the `confirm` command."""
@@ -62,10 +55,9 @@ class TestConfirm(unittest.TestCase):
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There should be one messages in the queue; the welcome message.
- messages = get_queue_messages('virgin')
- self.assertEqual(len(messages), 1)
+ items = get_queue_messages('virgin', expected_count=1)
# Grab the welcome message.
- welcome = messages[0].msg
+ welcome = items[0].msg
self.assertEqual(welcome['subject'],
'Welcome to the "Test" mailing list')
self.assertEqual(welcome['to'], 'Anne Person <anne@example.com>')
@@ -77,8 +69,7 @@ class TestConfirm(unittest.TestCase):
self._mlist, Message(), {}, (self._token,), Results())
self.assertEqual(status, ContinueProcessing.yes)
# There will be no messages in the queue.
- messages = get_queue_messages('virgin')
- self.assertEqual(len(messages), 0)
+ get_queue_messages('virgin', expected_count=0)
class TestEmailResponses(unittest.TestCase):
@@ -91,8 +82,8 @@ class TestEmailResponses(unittest.TestCase):
def test_confirm_then_moderate_workflow(self):
# Issue #114 describes a problem when confirming the moderation email.
- self._mlist.subscription_policy = \
- SubscriptionPolicy.confirm_then_moderate
+ self._mlist.subscription_policy = (
+ SubscriptionPolicy.confirm_then_moderate)
bart = getUtility(IUserManager).create_address(
'bart@example.com', 'Bart Person')
# Clear any previously queued confirmation messages.
@@ -101,8 +92,7 @@ class TestEmailResponses(unittest.TestCase):
bart)
# There should now be one email message in the virgin queue, i.e. the
# confirmation message sent to Bart.
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
msg = items[0].msg
# Confirmations come first, so this one goes to the subscriber.
self.assertEqual(msg['to'], 'bart@example.com')
@@ -123,8 +113,7 @@ class TestEmailResponses(unittest.TestCase):
# subscriber containing the results of their confirmation message, and
# the other is to the moderators informing them that they need to
# handle the moderation queue.
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
if items[0].msg['to'] == 'bart@example.com':
results = items[0].msg
moderator_msg = items[1].msg
diff --git a/src/mailman/commands/tests/test_control.py b/src/mailman/commands/tests/test_control.py
index 58702c70e..b25c63185 100644
--- a/src/mailman/commands/tests/test_control.py
+++ b/src/mailman/commands/tests/test_control.py
@@ -17,14 +17,6 @@
"""Test some additional corner cases for starting/stopping."""
-__all__ = [
- 'TestBinDir',
- 'TestStart',
- 'find_master',
- 'make_config',
- ]
-
-
import os
import sys
import time
@@ -34,7 +26,7 @@ import shutil
import socket
import unittest
-from contextlib import ExitStack
+from contextlib import ExitStack, suppress
from datetime import timedelta, datetime
from mailman.commands.cli_control import Start, kill_watcher
from mailman.config import Configuration, config
@@ -46,7 +38,6 @@ from tempfile import TemporaryDirectory
SEP = '|'
-
def make_config():
# All we care about is the master process; normally it starts a bunch of
# runners, but we don't care about any of them, so write a test
@@ -56,7 +47,7 @@ def make_config():
shutil.copyfile(config.filename, config_file)
with open(config_file, 'a') as fp:
for runner_config in config.runner_configs:
- print('[{0}]\nstart:no\n'.format(runner_config.name), file=fp)
+ print('[{}]\nstart:no\n'.format(runner_config.name), file=fp)
return config_file
@@ -83,7 +74,6 @@ def find_master():
return None
-
class FakeArgs:
force = None
run_as_user = None
@@ -100,7 +90,6 @@ class FakeParser:
sys.exit(1)
-
class TestStart(unittest.TestCase):
"""Test various starting scenarios."""
@@ -152,20 +141,17 @@ class TestStart(unittest.TestCase):
t = time.mktime(expiration_date.timetuple())
os.utime(claim_file, (t, t))
# Start without --force; no master will be running.
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
- self.assertEqual(find_master(), None)
- self.assertTrue('--force' in self.command.parser.message)
+ self.assertIsNone(find_master())
+ self.assertIn('--force', self.command.parser.message)
# Start again, this time with --force.
self.args.force = True
self.command.process(self.args)
pid = find_master()
- self.assertNotEqual(pid, None)
+ self.assertIsNotNone(pid)
-
class TestBinDir(unittest.TestCase):
"""Test issues related to bin_dir, e.g. issue #3"""
diff --git a/src/mailman/commands/tests/test_create.py b/src/mailman/commands/tests/test_create.py
index 97a8d895e..392dbdbb2 100644
--- a/src/mailman/commands/tests/test_create.py
+++ b/src/mailman/commands/tests/test_create.py
@@ -17,21 +17,16 @@
"""Test the `mailman create` subcommand."""
-__all__ = [
- 'TestCreate',
- ]
-
-
import sys
import unittest
from argparse import ArgumentParser
+from contextlib import suppress
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 = []
@@ -50,7 +45,6 @@ class FakeParser:
sys.exit(1)
-
class TestCreate(unittest.TestCase):
layer = ConfigLayer
@@ -63,20 +57,16 @@ class TestCreate(unittest.TestCase):
# Cannot create a mailing list if it already exists.
create_list('test@example.com')
self.args.listname = ['test@example.com']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
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']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'Illegal list name: foo')
@@ -84,10 +74,8 @@ class TestCreate(unittest.TestCase):
# Cannot create a list with invalid owner addresses. LP: #778687
self.args.listname = ['test@example.com']
self.args.owners = ['main=True']
- try:
+ with suppress(SystemExit):
self.command.process(self.args)
- except SystemExit:
- pass
self.assertEqual(self.command.parser.message,
'Illegal owner addresses: main=True')
diff --git a/src/mailman/commands/tests/test_digests.py b/src/mailman/commands/tests/test_digests.py
index 2fe59dc57..b14820cbd 100644
--- a/src/mailman/commands/tests/test_digests.py
+++ b/src/mailman/commands/tests/test_digests.py
@@ -17,12 +17,6 @@
"""Test the send-digests subcommand."""
-__all__ = [
- 'TestBumpVolume',
- 'TestSendDigests',
- ]
-
-
import os
import unittest
@@ -42,7 +36,6 @@ from mailman.utilities.datetime import now as right_now
from unittest.mock import patch
-
class FakeArgs:
def __init__(self):
self.lists = []
@@ -50,7 +43,6 @@ class FakeArgs:
self.bump = False
-
class TestSendDigests(unittest.TestCase):
layer = ConfigLayer
@@ -79,8 +71,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -91,8 +82,7 @@ Subject: message 1
# Now, there's no digest mbox and there's a plaintext digest in the
# outgoing queue.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -110,8 +100,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -122,8 +111,7 @@ Subject: message 1
# Now, there's no digest mbox and there's a plaintext digest in the
# outgoing queue.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -141,8 +129,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -157,8 +144,7 @@ Subject: message 1
'No such list found: bee.example.com\n')
# And no digest was prepared.
self.assertGreater(os.path.getsize(mailbox_path), 0)
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_send_one_digest_to_missing_fqdn_listname(self):
msg = mfs("""\
@@ -173,8 +159,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -189,8 +174,7 @@ Subject: message 1
'No such list found: bee@example.com\n')
# And no digest was prepared.
self.assertGreater(os.path.getsize(mailbox_path), 0)
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_send_digest_to_one_missing_and_one_existing_list(self):
msg = mfs("""\
@@ -205,8 +189,7 @@ Subject: message 1
self._handler.process(self._mlist, msg, {})
# There are no digests already being sent, but the ant mailing list
# does have a digest mbox collecting messages.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(mailbox_path), 0)
args = FakeArgs()
@@ -221,8 +204,7 @@ Subject: message 1
'No such list found: bee.example.com\n')
# But ant's digest was still prepared.
self.assertFalse(os.path.exists(mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
digest_contents = str(items[0].msg)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
@@ -265,8 +247,7 @@ Subject: message 3
bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
# Both.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
# Process both list's digests.
args = FakeArgs()
args.send = True
@@ -277,8 +258,7 @@ Subject: message 3
# digest in the outgoing queue for both.
self.assertFalse(os.path.exists(ant_mailbox_path))
self.assertFalse(os.path.exists(bee_mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
# Figure out which digest is going to ant and which to bee.
if items[0].msg['to'] == 'ant@example.com':
ant = items[0].msg
@@ -334,8 +314,7 @@ Subject: message 3
bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
# Both.
- items = get_queue_messages('digest')
- self.assertEqual(len(items), 0)
+ get_queue_messages('digest', expected_count=0)
# Process all mailing list digests by not setting any arguments.
args = FakeArgs()
args.send = True
@@ -345,8 +324,7 @@ Subject: message 3
# digest in the outgoing queue for both.
self.assertFalse(os.path.exists(ant_mailbox_path))
self.assertFalse(os.path.exists(bee_mailbox_path))
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 2)
+ items = get_queue_messages('virgin', expected_count=2)
# Figure out which digest is going to ant and which to bee.
if items[0].msg['to'] == 'ant@example.com':
ant = items[0].msg
@@ -374,8 +352,7 @@ Subject: message 3
args.lists.append('ant.example.com')
self._command.process(args)
self._runner.run()
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 0)
+ get_queue_messages('virgin', expected_count=0)
def test_bump_before_send(self):
self._mlist.digest_volume_frequency = DigestFrequency.monthly
@@ -401,12 +378,10 @@ Subject: message 1
self.assertEqual(self._mlist.volume, 8)
self.assertEqual(self._mlist.next_digest_number, 2)
self.assertEqual(self._mlist.digest_last_sent_at, right_now())
- items = get_queue_messages('virgin')
- self.assertEqual(len(items), 1)
+ items = get_queue_messages('virgin', expected_count=1)
self.assertEqual(items[0].msg['subject'], 'Ant Digest, Vol 8, Issue 1')
-
class TestBumpVolume(unittest.TestCase):
layer = ConfigLayer
diff --git a/src/mailman/commands/tests/test_help.py b/src/mailman/commands/tests/test_help.py
index 2155b21cd..a45fc7c6c 100644
--- a/src/mailman/commands/tests/test_help.py
+++ b/src/mailman/commands/tests/test_help.py
@@ -17,11 +17,6 @@
"""Additional tests for the `help` email command."""
-__all__ = [
- 'TestHelp',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -32,7 +27,6 @@ from mailman.runners.command import Results
from mailman.testing.layers import ConfigLayer
-
class TestHelp(unittest.TestCase):
"""Test email help."""
diff --git a/src/mailman/commands/tests/test_import.py b/src/mailman/commands/tests/test_import.py
index 59992c07b..32f6c4df9 100644
--- a/src/mailman/commands/tests/test_import.py
+++ b/src/mailman/commands/tests/test_import.py
@@ -17,11 +17,6 @@
"""Test the `mailman import21` subcommand."""
-__all__ = [
- 'TestImport',
- ]
-
-
import unittest
from mailman.app.lifecycle import create_list
@@ -31,7 +26,6 @@ from pkg_resources import resource_filename
from unittest.mock import patch
-
class FakeArgs:
listname = ['test@example.com']
pickle_file = [
@@ -39,7 +33,6 @@ class FakeArgs:
]
-
class TestImport(unittest.TestCase):
layer = ConfigLayer
diff --git a/src/mailman/commands/tests/test_lists.py b/src/mailman/commands/tests/test_lists.py
index d7cb2ce66..392e3f36e 100644
--- a/src/mailman/commands/tests/test_lists.py
+++ b/src/mailman/commands/tests/test_lists.py
@@ -17,11 +17,6 @@
"""Additional tests for the `lists` command line subcommand."""
-__all__ = [
- 'TestLists',
- ]
-
-
import unittest
from io import StringIO
diff --git a/src/mailman/commands/tests/test_members.py b/src/mailman/commands/tests/test_members.py
index 1ef9037b0..7f90da20b 100644
--- a/src/mailman/commands/tests/test_members.py
+++ b/src/mailman/commands/tests/test_members.py
@@ -17,11 +17,6 @@
"""Test the `mailman members` command."""
-__all__ = [
- 'TestCLIMembers',
- ]
-
-
import sys
import unittest
@@ -36,7 +31,6 @@ from tempfile import NamedTemporaryFile
from unittest.mock import patch
-
class FakeArgs:
input_filename = None
output_filename = None
@@ -56,7 +50,6 @@ class FakeParser:
sys.exit(1)
-
class TestCLIMembers(unittest.TestCase):
layer = ConfigLayer