From 7af50e2b346b76daab8206c448e5e67f06cbacbd Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Sat, 14 May 2011 07:06:54 +0200
Subject: Add tests for the outgoing queue runner.
* Use m.u.datetime.now() instead of datetime.now()
* Add a predicate argument to make_testable_runner() so that we can e.g. pass
in a function that causes the queue runner to run only once.
* Minor improvement to get_queue_messages() so that it doesn't need a lambda.
---
src/mailman/queue/tests/__init__.py | 0
src/mailman/queue/tests/test_outgoing.py | 87 ++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+)
create mode 100644 src/mailman/queue/tests/__init__.py
create mode 100644 src/mailman/queue/tests/test_outgoing.py
(limited to 'src/mailman/queue/tests')
diff --git a/src/mailman/queue/tests/__init__.py b/src/mailman/queue/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/mailman/queue/tests/test_outgoing.py b/src/mailman/queue/tests/test_outgoing.py
new file mode 100644
index 000000000..fc4eb3070
--- /dev/null
+++ b/src/mailman/queue/tests/test_outgoing.py
@@ -0,0 +1,87 @@
+# Copyright (C) 2011 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see .
+
+"""Test the outgoing queue runner."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'test_suite',
+ ]
+
+
+import datetime
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.queue.outgoing import OutgoingRunner
+from mailman.testing.helpers import (
+ get_queue_messages,
+ make_testable_runner,
+ specialized_message_from_string as message_from_string)
+from mailman.testing.layers import SMTPLayer
+from mailman.utilities.datetime import now
+
+
+
+def run_once(qrunner):
+ """Predicate for make_testable_runner().
+
+ Ensures that the queue runner only runs once.
+ """
+ return True
+
+
+
+class TestOnce(unittest.TestCase):
+ """Test outgoing runner message disposition."""
+
+ layer = SMTPLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._outq = config.switchboards['out']
+ self._runner = make_testable_runner(OutgoingRunner, 'out', run_once)
+ self._msg = message_from_string("""\
+From: anne@example.com
+To: test@example.com
+Message-Id:
+
+""")
+ self._msgdata = {}
+
+ def test_deliver_after(self):
+ # When the metadata has a deliver_after key in the future, the queue
+ # runner will re-enqueue the message rather than delivering it.
+ deliver_after = now() + datetime.timedelta(days=10)
+ self._msgdata['deliver_after'] = deliver_after
+ self._outq.enqueue(self._msg, self._msgdata, tolist=True,
+ listname='test@example.com')
+ self._runner.run()
+ items = get_queue_messages('out')
+ self.assertEqual(len(items), 1)
+ self.assertEqual(items[0].msgdata['deliver_after'], deliver_after)
+ self.assertEqual(items[0].msg['message-id'], '')
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestOnce))
+ return suite
--
cgit v1.2.3-70-g09d2