summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2013-10-18 18:18:46 -0400
committerBarry Warsaw2013-10-18 18:18:46 -0400
commit76efb4974c3b7fd71f74f8f460beacc3b917eaa9 (patch)
treec479d9d70d77cfeba116f882ab4d5859111087de
parent9aa16a276547fbb77eb15bd3cb2309b34aa58607 (diff)
downloadmailman-76efb4974c3b7fd71f74f8f460beacc3b917eaa9.tar.gz
mailman-76efb4974c3b7fd71f74f8f460beacc3b917eaa9.tar.zst
mailman-76efb4974c3b7fd71f74f8f460beacc3b917eaa9.zip
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/utilities/importer.py13
-rw-r--r--src/mailman/utilities/tests/test_import.py55
3 files changed, 70 insertions, 0 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 552b396ac..c149494b7 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -53,6 +53,8 @@ Bugs
signals. (LP: #1184376)
* Add `subject_prefix` to the `IMailingList` interface, and clarify the
docstring for `display_name`. (LP: #1181498)
+ * Fix importation from MM2.1 to MM3 of the archive policy. Given by Aurélien
+ Bompard. (LP: #1227658)
3.0 beta 3 -- "Here Again"
diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py
index f5aa8d10a..ef2324197 100644
--- a/src/mailman/utilities/importer.py
+++ b/src/mailman/utilities/importer.py
@@ -33,6 +33,7 @@ from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.digests import DigestFrequency
from mailman.interfaces.mailinglist import Personalization, ReplyToMunging
from mailman.interfaces.nntp import NewsgroupModeration
+from mailman.interfaces.archiver import ArchivePolicy
@@ -90,3 +91,15 @@ def import_config_pck(mlist, config_dict):
except TypeError:
print('Type conversion error:', key, file=sys.stderr)
raise
+ # Handle the archiving policy. In MM2.1 there were two boolean options
+ # but only three of the four possible states were valid. Now there's just
+ # an enum.
+ if config_dict.get('archive'):
+ # For maximum safety, if for some strange reason there's no
+ # archive_private key, treat the list as having private archives.
+ if config_dict.get('archive_private', True):
+ mlist.archive_policy = ArchivePolicy.private
+ else:
+ mlist.archive_policy = ArchivePolicy.public
+ else:
+ mlist.archive_policy = ArchivePolicy.never
diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py
index c8da32e42..b64da7501 100644
--- a/src/mailman/utilities/tests/test_import.py
+++ b/src/mailman/utilities/tests/test_import.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestArchiveImport',
'TestBasicImport',
]
@@ -29,6 +30,7 @@ import cPickle
import unittest
from mailman.app.lifecycle import create_list, remove_list
+from mailman.interfaces.archiver import ArchivePolicy
from mailman.testing.layers import ConfigLayer
from mailman.utilities.importer import import_config_pck
from pkg_resources import resource_filename
@@ -68,3 +70,56 @@ class TestBasicImport(unittest.TestCase):
self._import()
self.assertTrue(self._mlist.allow_list_posts)
self.assertTrue(self._mlist.include_rfc2369_headers)
+
+
+
+class TestArchiveImport(unittest.TestCase):
+ """Test conversion of the archive policies.
+
+ Mailman 2.1 had two variables `archive` and `archive_private`. Now
+ there's just a single `archive_policy` enum.
+ """
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('blank@example.com')
+ self._mlist.archive_policy = 'INITIAL-TEST-VALUE'
+
+ def _do_test(self, pckdict, expected):
+ import_config_pck(self._mlist, pckdict)
+ self.assertEqual(self._mlist.archive_policy, expected)
+
+ def test_public(self):
+ self._do_test(dict(archive=True, archive_private=False),
+ ArchivePolicy.public)
+
+ def test_private(self):
+ self._do_test(dict(archive=True, archive_private=True),
+ ArchivePolicy.private)
+
+ def test_no_archive(self):
+ self._do_test(dict(archive=False, archive_private=False),
+ ArchivePolicy.never)
+
+ def test_bad_state(self):
+ # For some reason, the old list has the invalid archiving state where
+ # `archive` is False and `archive_private` is True. It doesn't matter
+ # because this still collapses to the same enum value.
+ self._do_test(dict(archive=False, archive_private=True),
+ ArchivePolicy.never)
+
+ def test_missing_archive_key(self):
+ # For some reason, the old list didn't have an `archive` key. We
+ # treat this as if no archiving is done.
+ self._do_test(dict(archive_private=False), ArchivePolicy.never)
+
+ def test_missing_archive_key_archive_public(self):
+ # For some reason, the old list didn't have an `archive` key, and it
+ # has weird value for archive_private. We treat this as if no
+ # archiving is done.
+ self._do_test(dict(archive_private=True), ArchivePolicy.never)
+
+ def test_missing_archive_private_key(self):
+ # For some reason, the old list was missing an `archive_private` key.
+ # For maximum safety, we treat this as private archiving.
+ self._do_test(dict(archive=True), ArchivePolicy.private)