diff options
| author | Barry Warsaw | 2012-12-17 22:49:18 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2012-12-17 22:49:18 -0500 |
| commit | 875f4df48ece06fce8328e375ee1cae9c9408234 (patch) | |
| tree | 18a11e628dfcf13949eaf40695ea7801d1a51bd8 /src/mailman/app/tests/test_moderation.py | |
| parent | e47615a26cb31694439ce1ab27436c95bfc1f747 (diff) | |
| parent | 7d6069ad0411cecbb44e34838d53c48ba8598802 (diff) | |
| download | mailman-875f4df48ece06fce8328e375ee1cae9c9408234.tar.gz mailman-875f4df48ece06fce8328e375ee1cae9c9408234.tar.zst mailman-875f4df48ece06fce8328e375ee1cae9c9408234.zip | |
* Expose a REST API for membership change (subscriptions and unsubscriptions)
moderation. (LP: #1090753)
* Fixed `send_goodbye_message()`. (LP: #1091321)
Also:
* Rewrite and refactor request.rst into better documentation, moving
non-good-path tests into unittests. This doctest now only describes the
IRequests API, while the bulk of the moderation documentation now lives in
moderator.rst.
* When a subscription request is pended, the `delivery_mode` key is now just
the enum item's name, instead of the str() of the enum (which would include
the class name). We know it's always going to be a DeliveryMode enum.
* Refactor out the welcome_message calculation from the welcome_message_uri,
since the same algorithm can apply to goodbye_message_uri.
* When a _Request is retrieved, include the RequestType enum name in the data
dictionary (if there is one) under the `_request_type` key. Some APIs find
this useful, but it's not directly returned otherwise.
* For held messages via the REST API, flatten the `data` key into the
top-level JSON representation, exposing some of the _mod_* keys under their
non-_mod_* equivalent. Ignore _mod_* keys we don't care about. This is an
API change.
Diffstat (limited to 'src/mailman/app/tests/test_moderation.py')
| -rw-r--r-- | src/mailman/app/tests/test_moderation.py | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/mailman/app/tests/test_moderation.py b/src/mailman/app/tests/test_moderation.py index dc1217d67..8efffb48b 100644 --- a/src/mailman/app/tests/test_moderation.py +++ b/src/mailman/app/tests/test_moderation.py @@ -27,15 +27,18 @@ __all__ = [ import unittest +from zope.component import getUtility + from mailman.app.lifecycle import create_list from mailman.app.moderator import handle_message, hold_message from mailman.interfaces.action import Action +from mailman.interfaces.messages import IMessageStore from mailman.interfaces.requests import IListRequests from mailman.runners.incoming import IncomingRunner from mailman.runners.outgoing import OutgoingRunner from mailman.runners.pipeline import PipelineRunner from mailman.testing.helpers import ( - make_testable_runner, specialized_message_from_string) + get_queue_messages, make_testable_runner, specialized_message_from_string) from mailman.testing.layers import SMTPLayer from mailman.utilities.datetime import now @@ -48,6 +51,7 @@ class TestModeration(unittest.TestCase): def setUp(self): self._mlist = create_list('test@example.com') + self._request_db = IListRequests(self._mlist) self._msg = specialized_message_from_string("""\ From: anne@example.com To: test@example.com @@ -101,11 +105,10 @@ Message-ID: <alpha> request_id = hold_message(self._mlist, self._msg) handle_message(self._mlist, request_id, Action.defer) # The message is still in the pending requests. - requests_db = IListRequests(self._mlist) - key, data = requests_db.get_request(request_id) + key, data = self._request_db.get_request(request_id) self.assertEqual(key, '<alpha>') handle_message(self._mlist, request_id, Action.hold) - key, data = requests_db.get_request(request_id) + key, data = self._request_db.get_request(request_id) self.assertEqual(key, '<alpha>') def test_lp_1031391(self): @@ -115,6 +118,37 @@ Message-ID: <alpha> received_time = now() msgdata = dict(received_time=received_time) request_id = hold_message(self._mlist, self._msg, msgdata) - requests_db = IListRequests(self._mlist) - key, data = requests_db.get_request(request_id) + key, data = self._request_db.get_request(request_id) self.assertEqual(data['received_time'], received_time) + + def test_non_preserving_disposition(self): + # By default, disposed messages are not preserved. + request_id = hold_message(self._mlist, self._msg) + handle_message(self._mlist, request_id, Action.discard) + message_store = getUtility(IMessageStore) + self.assertIsNone(message_store.get_message_by_id('<alpha>')) + + def test_preserving_disposition(self): + # Preserving a message keeps it in the store. + request_id = hold_message(self._mlist, self._msg) + handle_message(self._mlist, request_id, Action.discard, preserve=True) + message_store = getUtility(IMessageStore) + preserved_message = message_store.get_message_by_id('<alpha>') + self.assertEqual(preserved_message['message-id'], '<alpha>') + + def test_preserve_and_forward(self): + # We can both preserve and forward the message. + request_id = hold_message(self._mlist, self._msg) + handle_message(self._mlist, request_id, Action.discard, + preserve=True, forward=['zack@example.com']) + # The message is preserved in the store. + message_store = getUtility(IMessageStore) + preserved_message = message_store.get_message_by_id('<alpha>') + self.assertEqual(preserved_message['message-id'], '<alpha>') + # And the forwarded message lives in the virgin queue. + messages = get_queue_messages('virgin') + self.assertEqual(len(messages), 1) + self.assertEqual(str(messages[0].msg['subject']), + 'Forward of moderated message') + self.assertEqual(messages[0].msgdata['recipients'], + ['zack@example.com']) |
