Commit f58d9ea9 authored by Barry Warsaw's avatar Barry Warsaw

Add a test and a fix for the no-args version of `mailman send-digests`.

parent 573e6094
......@@ -285,3 +285,69 @@ Subject: message 3
digest_contents = str(bee)
self.assertIn('Subject: message 3', digest_contents)
self.assertIn('Subject: message 4', digest_contents)
def test_send_digests_for_all_lists(self):
# Populate ant's digest.
msg = mfs("""\
To: [email protected]
From: [email protected]
Subject: message 1
""")
self._handler.process(self._mlist, msg, {})
del msg['subject']
msg['subject'] = 'message 2'
self._handler.process(self._mlist, msg, {})
# Create the second list.
bee = create_list('[email protected]')
bee.digests_enabled = True
bee.digest_size_threshold = 100000
bee.send_welcome_message = False
member = subscribe(bee, 'Bart')
member.preferences.delivery_mode = DeliveryMode.plaintext_digests
# Populate bee's digest.
msg = mfs("""\
To: [email protected]
From: [email protected]
Subject: message 3
""")
self._handler.process(bee, msg, {})
del msg['subject']
msg['subject'] = 'message 4'
self._handler.process(bee, msg, {})
# There are no digests for either list already being sent, but the
# mailing lists do have a digest mbox collecting messages.
ant_mailbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(ant_mailbox_path), 0)
# Check bee's digest.
bee_mailbox_path = os.path.join(bee.data_path, 'digest.mmdf')
self.assertGreater(os.path.getsize(bee_mailbox_path), 0)
# Both.
items = get_queue_messages('digest')
self.assertEqual(len(items), 0)
# Process all mailing list digests by not setting any arguments.
self._command.process(FakeArgs())
self._runner.run()
# Now, neither list has a digest mbox and but there are plaintext
# digest in the outgoing queue for both.
self.assertFalse(os.path.exists(ant_mailbox_path))
self.assertFalse(os.path.exists(bee_mailbox_path))
items = get_queue_messages('virgin')
self.assertEqual(len(items), 2)
# Figure out which digest is going to ant and which to bee.
if items[0].msg['to'] == '[email protected]':
ant = items[0].msg
bee = items[1].msg
else:
assert items[0].msg['to'] == '[email protected]'
ant = items[1].msg
bee = items[0].msg
# Check ant's digest.
digest_contents = str(ant)
self.assertIn('Subject: message 1', digest_contents)
self.assertIn('Subject: message 2', digest_contents)
# Check bee's digest.
digest_contents = str(bee)
self.assertIn('Subject: message 3', digest_contents)
self.assertIn('Subject: message 4', digest_contents)
......@@ -130,22 +130,23 @@ def maybe_send_digest_now(mlist=None, force=False):
# actually be, but it's the most easily available metric to decide
# whether the size threshold has been reached.
size = os.path.getsize(mailbox_path)
if (size >= mlist.digest_size_threshold * 1024.0 or
if (size >= mailing_list.digest_size_threshold * 1024.0 or
(force and size > 0)):
# Send the digest. Because we don't want to hold up this process
# with crafting the digest, we're going to move the digest file to
# a safe place, then craft a fake message for the DigestRunner as
# a trigger for it to build and send the digest.
mailbox_dest = os.path.join(
mlist.data_path,
'digest.{0.volume}.{0.next_digest_number}.mmdf'.format(mlist))
volume = mlist.volume
digest_number = mlist.next_digest_number
bump_digest_number_and_volume(mlist)
mailing_list.data_path,
'digest.{0.volume}.{0.next_digest_number}.mmdf'.format(
mailing_list))
volume = mailing_list.volume
digest_number = mailing_list.next_digest_number
bump_digest_number_and_volume(mailing_list)
os.rename(mailbox_path, mailbox_dest)
config.switchboards['digest'].enqueue(
Message(),
listid=mlist.list_id,
listid=mailing_list.list_id,
digest_path=mailbox_dest,
volume=volume,
digest_number=digest_number)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment