Barry Warsaw pushed to branch rename-metadata-key at mailman / Mailman Core
Commits: 8ebd97ee by Barry Warsaw at 2017-08-03T14:09:49-04:00 100% diffcov. Also, since the str() of the error object will contain the full details, use it in the log message when the pipeline processor gets a RejectMessage. - - - - - 3 changed files: - src/mailman/core/pipelines.py - src/mailman/core/tests/test_pipelines.py - src/mailman/interfaces/pipeline.py Changes: ===================================== src/mailman/core/pipelines.py ===================================== --- a/src/mailman/core/pipelines.py +++ b/src/mailman/core/pipelines.py @@ -55,7 +55,7 @@ def process(mlist, msg, msgdata, pipeline_name='built-in'): except RejectMessage as error: vlog.info( '{} rejected by "{}" pipeline handler "{}": {}'.format( - message_id, pipeline_name, handler.name, error.message)) + message_id, pipeline_name, handler.name, str(error))) bounce_message(mlist, msg, error) ===================================== src/mailman/core/tests/test_pipelines.py ===================================== --- a/src/mailman/core/tests/test_pipelines.py +++ b/src/mailman/core/tests/test_pipelines.py @@ -48,8 +48,11 @@ class DiscardingHandler: class RejectHandler: name = 'rejecting' + def __init__(self, message): + self.message = message + def process(self, mlist, msg, msgdata): - raise RejectMessage('by test handler') + raise RejectMessage(self.message) @implementer(IPipeline) @@ -66,8 +69,11 @@ class RejectingPipeline: name = 'test-rejecting' description = 'Rejectinging test pipeline' + def __init__(self): + self.message = 'by test handler' + def __iter__(self): - yield RejectHandler() + yield RejectHandler(self.message) class TestPostingPipeline(unittest.TestCase): @@ -109,18 +115,49 @@ testing '"discarding": by test handler')) def test_rejecting_pipeline(self): - # If a handler in the pipeline raises DiscardMessage, the message will - # be thrown away, but with a log message. + # If a handler in the pipeline raises RejectMessage, the post will + # be bounced with a log message. mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-rejecting') line = mark.readline()[:-1] - self.assertTrue(line.endswith( + self.assertEqual( + line[-80:], + '<ant> rejected by "test-rejecting" pipeline handler ' + '"rejecting": by test handler', + line) + # In the rejection case, the original message will also be in the + # virgin queue. + items = get_queue_messages('virgin', expected_count=1) + self.assertEqual( + str(items[0].msg.get_payload(1).get_payload(0)['subject']), + 'a test') + # The first payload contains the rejection reason. + payload = items[0].msg.get_payload(0).get_payload() + self.assertEqual(payload, 'by test handler') + + def test_rejecting_pipeline_without_message(self): + # Similar to above, but without a rejection message. + pipeline = config.pipelines['test-rejecting'] + message = pipeline.message + self.addCleanup(setattr, pipeline, 'message', message) + pipeline.message = None + mark = LogFileMark('mailman.vette') + process(self._mlist, self._msg, {}, 'test-rejecting') + line = mark.readline()[:-1] + self.assertEqual( + line[-91:], '<ant> rejected by "test-rejecting" pipeline handler ' - '"rejecting": by test handler')) + '"rejecting": [No details are available]', + line) # In the rejection case, the original message will also be in the # virgin queue. items = get_queue_messages('virgin', expected_count=1) - self.assertEqual(str(items[0].msg['subject']), 'a test') + self.assertEqual( + str(items[0].msg.get_payload(1).get_payload(0)['subject']), + 'a test') + # The first payload contains the rejection reason. + payload = items[0].msg.get_payload(0).get_payload() + self.assertEqual(payload, '[No details are available]') def test_decorate_bulk(self): # Ensure that bulk postings get decorated with the footer. ===================================== src/mailman/interfaces/pipeline.py ===================================== --- a/src/mailman/interfaces/pipeline.py +++ b/src/mailman/interfaces/pipeline.py @@ -50,7 +50,7 @@ class RejectMessage(BaseException): def __str__(self): if self.message is None: - return _('[No bounce details are available]') + return _('[No details are available]') reasons = (_('[No reasons given]') if self.reasons is None else NL.join(format_reasons(self.reasons))) View it on GitLab: https://gitlab.com/mailman/mailman/commit/8ebd97eeea71cb4faab76bd8c6d4f54672283d0c --- View it on GitLab: https://gitlab.com/mailman/mailman/commit/8ebd97eeea71cb4faab76bd8c6d4f54672283d0c You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org