From a8f2fc64c683420f40bac1b4c5d551305a0e0ecc Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Mon, 18 Jan 2016 18:25:03 +0100 Subject: Don't show the disabled archivers in the REST API Because one can't add a configuration overlay to the running REST server in testing mode, the prototype archiver was disabled in the testing configuration. This is where most of the changes in this commit come from. --- src/mailman/rest/docs/lists.rst | 4 ---- src/mailman/rest/lists.py | 6 ++++-- src/mailman/rest/tests/test_lists.py | 10 ++++------ src/mailman/testing/testing.cfg | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst index 6554b04c2..0fb877722 100644 --- a/src/mailman/rest/docs/lists.rst +++ b/src/mailman/rest/docs/lists.rst @@ -250,7 +250,6 @@ archivers are available, and whether they are enabled for this mailing list. http_etag: "..." mail-archive: True mhonarc: True - prototype: True You can set all the archiver states by putting new state flags on the resource. @@ -260,7 +259,6 @@ resource. ... 'http://localhost:9001/3.0/lists/dog@example.com/archivers', { ... 'mail-archive': False, ... 'mhonarc': True, - ... 'prototype': False, ... }, method='PUT') content-length: 0 date: ... @@ -271,7 +269,6 @@ resource. http_etag: "..." mail-archive: False mhonarc: True - prototype: False You can change the state of a subset of the list archivers. :: @@ -289,7 +286,6 @@ You can change the state of a subset of the list archivers. http_etag: "..." mail-archive: False mhonarc: False - prototype: False List digests diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index c3919c001..8e82cd1a4 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -330,13 +330,15 @@ class ListArchivers: """Get all the archiver statuses.""" archiver_set = IListArchiverSet(self._mlist) resource = {archiver.name: archiver.is_enabled - for archiver in archiver_set.archivers} + for archiver in archiver_set.archivers + if archiver.system_archiver.is_enabled} okay(response, etag(resource)) def patch_put(self, request, response, is_optional): archiver_set = IListArchiverSet(self._mlist) kws = {archiver.name: ArchiverGetterSetter(self._mlist) - for archiver in archiver_set.archivers} + for archiver in archiver_set.archivers + if archiver.system_archiver.is_enabled} if is_optional: # For a PATCH, all attributes are optional. kws['_optional'] = kws.keys() diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index 787009855..d83f70058 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -32,7 +32,7 @@ from mailman.interfaces.usermanager import IUserManager from mailman.model.mailinglist import AcceptableAlias from mailman.runners.digest import DigestRunner from mailman.testing.helpers import ( - call_api, get_queue_messages, make_testable_runner, + call_api, configuration, get_queue_messages, make_testable_runner, specialized_message_from_string as mfs) from mailman.testing.layers import RESTLayer from mailman.utilities.datetime import now as right_now @@ -339,7 +339,6 @@ class TestListArchivers(unittest.TestCase): self.assertEqual(resource, { 'mail-archive': True, 'mhonarc': True, - 'prototype': True, }) def test_archiver_statuses_on_missing_lists(self): @@ -375,7 +374,7 @@ class TestListArchivers(unittest.TestCase): def test_put_incomplete_statuses(self): # PUT requires the full resource representation. This one forgets to - # specify the prototype and mhonarc archiver. + # specify the mhonarc archiver. with self.assertRaises(HTTPError) as cm: call_api( 'http://localhost:9001/3.0/lists/ant.example.com/archivers', { @@ -384,7 +383,7 @@ class TestListArchivers(unittest.TestCase): method='PUT') self.assertEqual(cm.exception.code, 400) self.assertEqual(cm.exception.reason, - b'Missing parameters: mhonarc, prototype') + b'Missing parameters: mhonarc') def test_patch_bogus_status(self): # Archiver statuses must be interpretable as booleans. @@ -392,8 +391,7 @@ class TestListArchivers(unittest.TestCase): call_api( 'http://localhost:9001/3.0/lists/ant.example.com/archivers', { 'mail-archive': 'sure', - 'mhonarc': False, - 'prototype': 'no' + 'mhonarc': 'no' }, method='PATCH') self.assertEqual(cm.exception.code, 400) diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index 022f9f289..8b6a48c36 100644 --- a/src/mailman/testing/testing.cfg +++ b/src/mailman/testing/testing.cfg @@ -65,7 +65,7 @@ max_restarts: 1 max_restarts: 1 [archiver.prototype] -enable: yes +enable: no [archiver.mail_archive] enable: yes -- cgit v1.3.1 From accc4f1a883d4a5757eb9b0156e58e72b77a8af7 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Thu, 21 Jan 2016 11:46:49 +0100 Subject: Fix tests --- src/mailman/config/tests/test_archivers.py | 6 +++--- src/mailman/model/tests/test_mailinglist.py | 14 +++++++------- src/mailman/rest/tests/test_lists.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mailman/config/tests/test_archivers.py b/src/mailman/config/tests/test_archivers.py index 322a5040d..b09b89273 100644 --- a/src/mailman/config/tests/test_archivers.py +++ b/src/mailman/config/tests/test_archivers.py @@ -28,11 +28,11 @@ class TestArchivers(unittest.TestCase): layer = ConfigLayer def test_enabled(self): - # By default, the testing configuration enables the archivers. + # By default, the testing configuration enables some archivers. archivers = {} for archiver in config.archivers: archivers[archiver.name] = archiver - self.assertTrue(archivers['prototype'].is_enabled) + self.assertFalse(archivers['prototype'].is_enabled) self.assertTrue(archivers['mail-archive'].is_enabled) self.assertTrue(archivers['mhonarc'].is_enabled) @@ -42,6 +42,6 @@ class TestArchivers(unittest.TestCase): archivers = {} for archiver in config.archivers: archivers[archiver.name] = archiver - self.assertTrue(archivers['prototype'].is_enabled) + self.assertFalse(archivers['prototype'].is_enabled) self.assertTrue(archivers['mail-archive'].is_enabled) self.assertFalse(archivers['mhonarc'].is_enabled) diff --git a/src/mailman/model/tests/test_mailinglist.py b/src/mailman/model/tests/test_mailinglist.py index c9aecc93b..0f37fa2f3 100644 --- a/src/mailman/model/tests/test_mailinglist.py +++ b/src/mailman/model/tests/test_mailinglist.py @@ -108,11 +108,11 @@ class TestListArchiver(unittest.TestCase): def test_get_archiver(self): # Use .get() to see if a mailing list has an archiver. - archiver = self._set.get('prototype') - self.assertEqual(archiver.name, 'prototype') + archiver = self._set.get('mhonarc') + self.assertEqual(archiver.name, 'mhonarc') self.assertTrue(archiver.is_enabled) self.assertEqual(archiver.mailing_list, self._mlist) - self.assertEqual(archiver.system_archiver.name, 'prototype') + self.assertEqual(archiver.system_archiver.name, 'mhonarc') def test_get_archiver_no_such(self): # Using .get() on a non-existing name returns None. @@ -124,15 +124,15 @@ class TestListArchiver(unittest.TestCase): # then the site-wide archiver gets disabled, so the list specific # archiver will also be disabled. archiver_set = IListArchiverSet(self._mlist) - archiver = archiver_set.get('prototype') + archiver = archiver_set.get('mhonarc') self.assertTrue(archiver.is_enabled) # Disable the site-wide archiver. - config.push('enable prototype', """\ - [archiver.prototype] + config.push('enable mhonarc', """\ + [archiver.mhonarc] enable: no """) self.assertFalse(archiver.is_enabled) - config.pop('enable prototype') + config.pop('enable mhonarc') class TestDisabledListArchiver(unittest.TestCase): diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index d83f70058..3bee23314 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -32,7 +32,7 @@ from mailman.interfaces.usermanager import IUserManager from mailman.model.mailinglist import AcceptableAlias from mailman.runners.digest import DigestRunner from mailman.testing.helpers import ( - call_api, configuration, get_queue_messages, make_testable_runner, + call_api, get_queue_messages, make_testable_runner, specialized_message_from_string as mfs) from mailman.testing.layers import RESTLayer from mailman.utilities.datetime import now as right_now -- cgit v1.3.1