summaryrefslogtreecommitdiff
path: root/src/mailman/utilities/tests
diff options
context:
space:
mode:
authorBarry Warsaw2016-03-25 19:03:05 -0400
committerBarry Warsaw2016-03-25 19:03:05 -0400
commitc81e250e3a5690e8c8f9f4dc4b460c2a81731c48 (patch)
tree8152b01042ce3cd9a2f118759cbab7193f41b64e /src/mailman/utilities/tests
parent01433eedaeea07b72bfc8b2a970a1e0023975cd6 (diff)
downloadmailman-c81e250e3a5690e8c8f9f4dc4b460c2a81731c48.tar.gz
mailman-c81e250e3a5690e8c8f9f4dc4b460c2a81731c48.tar.zst
mailman-c81e250e3a5690e8c8f9f4dc4b460c2a81731c48.zip
Diffstat (limited to 'src/mailman/utilities/tests')
-rw-r--r--src/mailman/utilities/tests/test_email.py9
-rw-r--r--src/mailman/utilities/tests/test_import.py149
-rw-r--r--src/mailman/utilities/tests/test_passwords.py6
-rw-r--r--src/mailman/utilities/tests/test_queries.py5
-rw-r--r--src/mailman/utilities/tests/test_string.py6
-rw-r--r--src/mailman/utilities/tests/test_templates.py36
-rw-r--r--src/mailman/utilities/tests/test_uid.py8
-rw-r--r--src/mailman/utilities/tests/test_wrap.py6
8 files changed, 82 insertions, 143 deletions
diff --git a/src/mailman/utilities/tests/test_email.py b/src/mailman/utilities/tests/test_email.py
index d5bc5a560..36ffa7535 100644
--- a/src/mailman/utilities/tests/test_email.py
+++ b/src/mailman/utilities/tests/test_email.py
@@ -17,12 +17,6 @@
"""Testing functions in the email utilities."""
-__all__ = [
- 'TestEmail',
- 'TestMessageIDHash',
- ]
-
-
import unittest
from mailman.interfaces.messages import IMessageStore
@@ -33,7 +27,6 @@ from mailman.utilities.email import add_message_hash, split_email
from zope.component import getUtility
-
class TestEmail(unittest.TestCase):
"""Testing functions in the email utilities."""
@@ -119,9 +112,7 @@ Message-ID: aardvark>
self.assertEqual(hash32, '5KH3RA7ZM4VM6XOZXA7AST2XN2X4S3WY')
-
class TestMessageIDHash(unittest.TestCase):
-
layer = ConfigLayer
def setUp(self):
diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py
index 68a005760..637f78585 100644
--- a/src/mailman/utilities/tests/test_import.py
+++ b/src/mailman/utilities/tests/test_import.py
@@ -17,17 +17,6 @@
"""Tests for config.pck imports."""
-__all__ = [
- 'TestArchiveImport',
- 'TestBasicImport',
- 'TestConvertToURI',
- 'TestFilterActionImport',
- 'TestMemberActionImport',
- 'TestPreferencesImport',
- 'TestRosterImport',
- ]
-
-
import os
import unittest
@@ -61,7 +50,6 @@ from unittest import mock
from zope.component import getUtility
-
NL = '\n'
@@ -74,7 +62,6 @@ def list_to_string(data):
return NL.join(data).encode('utf-8')
-
class TestBasicImport(unittest.TestCase):
layer = ConfigLayer
@@ -148,9 +135,9 @@ class TestBasicImport(unittest.TestCase):
self.assertEqual(self._mlist.autoresponse_owner_text, '')
def test_administrativia(self):
- self._mlist.administrivia = None
- self._import()
- self.assertTrue(self._mlist.administrivia)
+ self._mlist.administrivia = None
+ self._import()
+ self.assertTrue(self._mlist.administrivia)
def test_filter_pass_renames(self):
# mime_types -> types
@@ -164,8 +151,9 @@ class TestBasicImport(unittest.TestCase):
self.assertEqual(list(self._mlist.filter_extensions),
['exe', 'bat', 'cmd', 'com', 'pif',
'scr', 'vbs', 'cpl'])
- self.assertEqual(list(self._mlist.pass_types),
- ['multipart/mixed', 'multipart/alternative', 'text/plain'])
+ self.assertEqual(
+ list(self._mlist.pass_types),
+ ['multipart/mixed', 'multipart/alternative', 'text/plain'])
self.assertEqual(list(self._mlist.pass_extensions), [])
def test_process_bounces(self):
@@ -249,7 +237,7 @@ class TestBasicImport(unittest.TestCase):
def test_acceptable_aliases_as_list(self):
# In some versions of the pickle, this can be a list, not a string
# (seen in the wild).
- aliases = [b'alias1@example.com', b'alias2@exemple.com' ]
+ aliases = [b'alias1@example.com', b'alias2@exemple.com']
self._pckdict['acceptable_aliases'] = aliases
self._import()
alias_set = IAcceptableAliasSet(self._mlist)
@@ -368,40 +356,40 @@ class TestBasicImport(unittest.TestCase):
self._import()
self.assertListEqual(
[(hm.header, hm.pattern, hm.chain)
- for hm in self._mlist.header_matches ], [
- ('x-spam-status', 'Yes.*', 'discard'),
- ('x-spam-status', 'Yes', 'reject'),
- ('x-spam-level', '\\*\\*\\*.*$', 'discard'),
- ('x-spam-level', '\\*\\*', 'discard'),
- ('x-spam', '\\Yes', 'discard'),
- ('subject', '\\[SPAM\\].*', 'discard'),
- ('subject', '.*loan.*', 'discard'),
- ('original-received', 'from *linkedin.com*', 'discard'),
- ('x-git-module', 'rhq.*git', 'accept'),
- ('approved', 'verysecretpassword', 'accept'),
- ('subject', 'dev-', 'discard'),
- ('subject', 'staging-', 'discard'),
- ('from', '.*info@aolanchem.com', 'reject'),
- ('from', '.*@jw-express.com', 'reject'),
- ('received', 'from smtp-.*\\.fedoraproject\\.org', 'hold'),
- ('received', 'from mx.*\\.redhat.com', 'hold'),
- ('resent-date', '.*', 'hold'),
- ('resent-from', '.*', 'hold'),
- ('resent-message-id', '.*', 'hold'),
- ('resent-to', '.*', 'hold'),
- ('subject', '[^mtv]', 'hold'),
- ('received', 'from fedorahosted\\.org.*by fedorahosted\\.org',
- 'accept'),
- ('received',
- 'from hosted.*\\.fedoraproject.org.*by '
- 'hosted.*\\.fedoraproject\\.org', 'accept'),
- ('received',
- 'from hosted.*\\.fedoraproject.org.*by '
- 'fedoraproject\\.org', 'accept'),
- ('received',
- 'from hosted.*\\.fedoraproject.org.*by '
- 'fedorahosted\\.org', 'accept'),
- ])
+ for hm in self._mlist.header_matches], [
+ ('x-spam-status', 'Yes.*', 'discard'),
+ ('x-spam-status', 'Yes', 'reject'),
+ ('x-spam-level', '\\*\\*\\*.*$', 'discard'),
+ ('x-spam-level', '\\*\\*', 'discard'),
+ ('x-spam', '\\Yes', 'discard'),
+ ('subject', '\\[SPAM\\].*', 'discard'),
+ ('subject', '.*loan.*', 'discard'),
+ ('original-received', 'from *linkedin.com*', 'discard'),
+ ('x-git-module', 'rhq.*git', 'accept'),
+ ('approved', 'verysecretpassword', 'accept'),
+ ('subject', 'dev-', 'discard'),
+ ('subject', 'staging-', 'discard'),
+ ('from', '.*info@aolanchem.com', 'reject'),
+ ('from', '.*@jw-express.com', 'reject'),
+ ('received', 'from smtp-.*\\.fedoraproject\\.org', 'hold'),
+ ('received', 'from mx.*\\.redhat.com', 'hold'),
+ ('resent-date', '.*', 'hold'),
+ ('resent-from', '.*', 'hold'),
+ ('resent-message-id', '.*', 'hold'),
+ ('resent-to', '.*', 'hold'),
+ ('subject', '[^mtv]', 'hold'),
+ ('received', 'from fedorahosted\\.org.*by fedorahosted\\.org',
+ 'accept'),
+ ('received',
+ 'from hosted.*\\.fedoraproject.org.*by '
+ 'hosted.*\\.fedoraproject\\.org', 'accept'),
+ ('received',
+ 'from hosted.*\\.fedoraproject.org.*by '
+ 'fedoraproject\\.org', 'accept'),
+ ('received',
+ 'from hosted.*\\.fedoraproject.org.*by '
+ 'fedorahosted\\.org', 'accept'),
+ ])
loglines = error_log.read().strip()
self.assertEqual(len(loglines), 0)
@@ -484,7 +472,6 @@ class TestBasicImport(unittest.TestCase):
error_log.readline())
-
class TestArchiveImport(unittest.TestCase):
"""Test conversion of the archive policies.
@@ -537,7 +524,6 @@ class TestArchiveImport(unittest.TestCase):
self._do_test(dict(archive=True), ArchivePolicy.private)
-
class TestFilterActionImport(unittest.TestCase):
# The mlist.filter_action enum values have changed. In Mailman 2.1 the
# order was 'Discard', 'Reject', 'Forward to List Owner', 'Preserve'.
@@ -565,7 +551,6 @@ class TestFilterActionImport(unittest.TestCase):
self._do_test(3, FilterAction.preserve)
-
class TestMemberActionImport(unittest.TestCase):
# The mlist.default_member_action and mlist.default_nonmember_action enum
# values are different in Mailman 2.1; they have been merged into a
@@ -637,7 +622,6 @@ class TestMemberActionImport(unittest.TestCase):
self._do_test(dict(default_nonmember_action=Action.discard))
-
class TestConvertToURI(unittest.TestCase):
# The following values were plain text, and are now URIs in Mailman 3:
# - welcome_message_uri
@@ -673,9 +657,10 @@ class TestConvertToURI(unittest.TestCase):
import_config_pck(self._mlist, self._pckdict)
newattr = getattr(self._mlist, newvar)
text = decorate(self._mlist, newattr)
- self.assertEqual(text, 'TEST VALUE',
- 'Old variable %s was not properly imported to %s'
- % (oldvar, newvar))
+ self.assertEqual(
+ text, 'TEST VALUE',
+ 'Old variable %s was not properly imported to %s'
+ % (oldvar, newvar))
def test_substitutions(self):
test_text = ('UNIT TESTING %(real_name)s mailing list\n'
@@ -712,8 +697,9 @@ class TestConvertToURI(unittest.TestCase):
old_value = getattr(self._mlist, newvar)
import_config_pck(self._mlist, self._pckdict)
new_value = getattr(self._mlist, newvar)
- self.assertEqual(old_value, new_value,
- 'Default value was not preserved for %s' % newvar)
+ self.assertEqual(
+ old_value, new_value,
+ 'Default value was not preserved for %s' % newvar)
def test_keep_default_if_fqdn_changed(self):
# Use case: importing the old a@ex.com into b@ex.com. We can't check
@@ -729,7 +715,8 @@ class TestConvertToURI(unittest.TestCase):
with mock.patch('sys.stderr'):
import_config_pck(self._mlist, self._pckdict)
new_value = getattr(self._mlist, newvar)
- self.assertEqual(old_value, new_value,
+ self.assertEqual(
+ old_value, new_value,
'Default value was not preserved for %s' % newvar)
def test_unicode(self):
@@ -758,7 +745,7 @@ class TestConvertToURI(unittest.TestCase):
text = decorate(self._mlist, self._mlist.footer_uri)
self.assertEqual(text, 'NEW-VALUE')
-
+
class TestRosterImport(unittest.TestCase):
"""Test that rosters are imported correctly."""
@@ -776,22 +763,23 @@ class TestRosterImport(unittest.TestCase):
'dave@example.com': b'dave@ExampLe.Com',
},
'passwords': {
- 'anne@example.com' : b'annepass',
- 'bob@example.com' : b'bobpass',
+ 'anne@example.com': b'annepass',
+ 'bob@example.com': b'bobpass',
'cindy@example.com': b'cindypass',
- 'dave@example.com' : b'davepass',
+ 'dave@example.com': b'davepass',
},
'language': {
- 'anne@example.com' : b'fr',
- 'bob@example.com' : b'de',
+ 'anne@example.com': b'fr',
+ 'bob@example.com': b'de',
'cindy@example.com': b'es',
- 'dave@example.com' : b'it',
+ 'dave@example.com': b'it',
},
- 'usernames': { # Usernames are unicode strings in the pickle
- 'anne@example.com' : 'Anne',
- 'bob@example.com' : 'Bob',
+ # Usernames are unicode strings in the pickle
+ 'usernames': {
+ 'anne@example.com': 'Anne',
+ 'bob@example.com': 'Bob',
'cindy@example.com': 'Cindy',
- 'dave@example.com' : 'Dave',
+ 'dave@example.com': 'Dave',
},
'owner': [
'anne@example.com',
@@ -878,9 +866,11 @@ class TestRosterImport(unittest.TestCase):
self.assertIsNotNone(user, 'User %s was not imported' % addr)
self.assertIsNotNone(address, 'Address %s was not imported' % addr)
display_name = self._pckdict['usernames'][addr]
- self.assertEqual(user.display_name, display_name,
+ self.assertEqual(
+ user.display_name, display_name,
'The display name was not set for User %s' % addr)
- self.assertEqual(address.display_name, display_name,
+ self.assertEqual(
+ address.display_name, display_name,
'The display name was not set for Address %s' % addr)
def test_owner(self):
@@ -907,7 +897,7 @@ class TestRosterImport(unittest.TestCase):
'Address fred@ was wrongly added to the members list')
def test_password(self):
- #self.anne.password = config.password_context.encrypt('abc123')
+ # self.anne.password = config.password_context.encrypt('abc123')
import_config_pck(self._mlist, self._pckdict)
for name in ('anne', 'bob', 'cindy', 'dave'):
addr = '%s@example.com' % name
@@ -920,7 +910,7 @@ class TestRosterImport(unittest.TestCase):
def test_same_user(self):
# Adding the address of an existing User must not create another user.
user = self._usermanager.create_user('anne@example.com', 'Anne')
- user.register('bob@example.com') # secondary email
+ user.register('bob@example.com') # secondary email
import_config_pck(self._mlist, self._pckdict)
member = self._mlist.members.get_member('bob@example.com')
self.assertEqual(member.user, user)
@@ -1023,7 +1013,6 @@ class TestRosterImport(unittest.TestCase):
self.assertTrue(all(addr.startswith('^') for addr in list_prop))
-
class TestPreferencesImport(unittest.TestCase):
"""Preferences get imported too."""
@@ -1124,7 +1113,7 @@ class TestPreferencesImport(unittest.TestCase):
def test_no_moderate(self):
# If option flag Moderate is not set, action is accept
- self._pckdict['member_moderation_action'] = 1 # reject
+ self._pckdict['member_moderation_action'] = 1 # reject
self._do_test(0, dict(moderation_action=Action.accept))
def test_multiple_options(self):
diff --git a/src/mailman/utilities/tests/test_passwords.py b/src/mailman/utilities/tests/test_passwords.py
index 326e1ac08..15f307007 100644
--- a/src/mailman/utilities/tests/test_passwords.py
+++ b/src/mailman/utilities/tests/test_passwords.py
@@ -17,11 +17,6 @@
"""Testing the password utility."""
-__all__ = [
- 'TestPasswords',
- ]
-
-
import os
import unittest
@@ -30,7 +25,6 @@ from mailman.testing.helpers import configuration
from mailman.testing.layers import ConfigLayer
-
class TestPasswords(unittest.TestCase):
layer = ConfigLayer
diff --git a/src/mailman/utilities/tests/test_queries.py b/src/mailman/utilities/tests/test_queries.py
index 39ab7de61..e5b0a7836 100644
--- a/src/mailman/utilities/tests/test_queries.py
+++ b/src/mailman/utilities/tests/test_queries.py
@@ -17,11 +17,6 @@
"""Test queries."""
-__all__ = [
- 'TestQueries',
- ]
-
-
import unittest
from mailman.utilities.queries import QuerySequence
diff --git a/src/mailman/utilities/tests/test_string.py b/src/mailman/utilities/tests/test_string.py
index ea3b94ee4..14beead0a 100644
--- a/src/mailman/utilities/tests/test_string.py
+++ b/src/mailman/utilities/tests/test_string.py
@@ -17,17 +17,11 @@
"""Test the string utilities."""
-__all__ = [
- 'TestString',
- ]
-
-
import unittest
from mailman.utilities import string
-
class TestString(unittest.TestCase):
def test_oneline_bogus_charset(self):
self.assertEqual(string.oneline('foo', 'bogus'), 'foo')
diff --git a/src/mailman/utilities/tests/test_templates.py b/src/mailman/utilities/tests/test_templates.py
index f4b581b90..9fb0aaa16 100644
--- a/src/mailman/utilities/tests/test_templates.py
+++ b/src/mailman/utilities/tests/test_templates.py
@@ -17,13 +17,6 @@
"""Testing i18n template search and interpolation."""
-__all__ = [
- 'TestFind',
- 'TestMake',
- 'TestSearchOrder',
- ]
-
-
import os
import shutil
import tempfile
@@ -38,7 +31,6 @@ from pkg_resources import resource_filename
from zope.component import getUtility
-
class TestSearchOrder(unittest.TestCase):
"""Test internal search order for language templates."""
@@ -51,7 +43,7 @@ class TestSearchOrder(unittest.TestCase):
[mailman]
default_language: fr
[paths.testing]
- var_dir: {0}
+ var_dir: {}
""".format(self.var_dir))
self.addCleanup(config.pop, 'no template dir')
self.mlist = create_list('l@example.com')
@@ -85,7 +77,7 @@ class TestSearchOrder(unittest.TestCase):
def test_fully_specified_search_order(self):
search_order = self._stripped_search_order('foo.txt', self.mlist, 'it')
# For convenience.
- def nexteq(path):
+ def nexteq(path): # flake8: noqa
self.assertEqual(next(search_order), path)
# 1: Use the given language argument
nexteq('/v/templates/lists/l.example.com/it/foo.txt')
@@ -115,7 +107,7 @@ class TestSearchOrder(unittest.TestCase):
def test_no_language_argument_search_order(self):
search_order = self._stripped_search_order('foo.txt', self.mlist)
# For convenience.
- def nexteq(path):
+ def nexteq(path): # flakeq: noqa
self.assertEqual(next(search_order), path)
# 1: Use mlist.preferred_language
nexteq('/v/templates/lists/l.example.com/de/foo.txt')
@@ -140,7 +132,7 @@ class TestSearchOrder(unittest.TestCase):
def test_no_mailing_list_argument_search_order(self):
search_order = self._stripped_search_order('foo.txt', language='it')
# For convenience.
- def nexteq(path):
+ def nexteq(path): # flake8: noqa
self.assertEqual(next(search_order), path)
# 1: Use the given language argument
nexteq('/v/templates/site/it/foo.txt')
@@ -156,7 +148,7 @@ class TestSearchOrder(unittest.TestCase):
def test_no_optional_arguments_search_order(self):
search_order = self._stripped_search_order('foo.txt')
# For convenience.
- def nexteq(path):
+ def nexteq(path): # flake8: noqa
self.assertEqual(next(search_order), path)
# 1: Use the site's default language
nexteq('/v/templates/site/fr/foo.txt')
@@ -168,7 +160,6 @@ class TestSearchOrder(unittest.TestCase):
nexteq('/m/templates/en/foo.txt')
-
class TestFind(unittest.TestCase):
"""Test template search."""
@@ -176,10 +167,12 @@ class TestFind(unittest.TestCase):
def setUp(self):
self.var_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.var_dir)
config.push('template config', """\
[paths.testing]
- var_dir: {0}
+ var_dir: {}
""".format(self.var_dir))
+ self.addCleanup(config.pop, 'template config')
# The following MUST happen AFTER the push() above since pushing a new
# config also clears out the language manager.
getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia')
@@ -187,7 +180,7 @@ class TestFind(unittest.TestCase):
self.mlist.preferred_language = 'xx'
self.fp = None
# Populate the template directories with a few fake templates.
- def write(text, path):
+ def write(text, path): # flake8: noqa
os.makedirs(os.path.dirname(path))
with open(path, 'w') as fp:
fp.write(text)
@@ -206,8 +199,6 @@ class TestFind(unittest.TestCase):
def tearDown(self):
if self.fp is not None:
self.fp.close()
- config.pop('template config')
- shutil.rmtree(self.var_dir)
def test_find_site_template(self):
filename, self.fp = find('site.txt', language='xx')
@@ -230,7 +221,6 @@ class TestFind(unittest.TestCase):
self.assertEqual(cm.exception.template_file, 'missing.txt')
-
class TestMake(unittest.TestCase):
"""Test template interpolation."""
@@ -238,10 +228,12 @@ class TestMake(unittest.TestCase):
def setUp(self):
self.var_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.var_dir)
config.push('template config', """\
[paths.testing]
- var_dir: {0}
+ var_dir: {}
""".format(self.var_dir))
+ self.addCleanup(config.pop, 'template config')
# The following MUST happen AFTER the push() above since pushing a new
# config also clears out the language manager.
getUtility(ILanguageManager).add('xx', 'utf-8', 'Xlandia')
@@ -269,10 +261,6 @@ It has $howmany substitutions.
It will not be wrapped.
""", file=fp)
- def tearDown(self):
- config.pop('template config')
- shutil.rmtree(self.var_dir)
-
def test_no_substitutions(self):
self.assertEqual(make('nosub.txt', self.mlist), """\
This is a global template. It has no substitutions. It will be
diff --git a/src/mailman/utilities/tests/test_uid.py b/src/mailman/utilities/tests/test_uid.py
index dce63caf3..0ee53a211 100644
--- a/src/mailman/utilities/tests/test_uid.py
+++ b/src/mailman/utilities/tests/test_uid.py
@@ -17,11 +17,6 @@
"""Test the uid module."""
-__all__ = [
- 'TestUID',
- ]
-
-
import os
import uuid
import unittest
@@ -33,7 +28,6 @@ from mailman.utilities import uid
from unittest.mock import patch
-
class TestUID(unittest.TestCase):
layer = ConfigLayer
@@ -60,7 +54,7 @@ class TestUID(unittest.TestCase):
def test_uid_record_try_again(self):
called = False
- def record_second(ignore):
+ def record_second(ignore): # flake8: noqa
nonlocal called
if not called:
called = True
diff --git a/src/mailman/utilities/tests/test_wrap.py b/src/mailman/utilities/tests/test_wrap.py
index bcb44eece..f34627694 100644
--- a/src/mailman/utilities/tests/test_wrap.py
+++ b/src/mailman/utilities/tests/test_wrap.py
@@ -17,17 +17,11 @@
"""Test text wrapping."""
-__all__ = [
- 'TestWrap',
- ]
-
-
import unittest
from mailman.utilities.string import wrap
-
class TestWrap(unittest.TestCase):
"""Test text wrapping."""