diff options
| author | Barry Warsaw | 2007-06-28 01:11:50 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2007-06-28 01:11:50 -0400 |
| commit | 14396f2d9f3a0c19ec340d664390d62192f74f54 (patch) | |
| tree | c9f77ea7018f56d7db2284f18520129067d81e7d /Mailman/Queue | |
| parent | 4053185269d20fff1e4cef20017eeef2d343be92 (diff) | |
| download | mailman-14396f2d9f3a0c19ec340d664390d62192f74f54.tar.gz mailman-14396f2d9f3a0c19ec340d664390d62192f74f54.tar.zst mailman-14396f2d9f3a0c19ec340d664390d62192f74f54.zip | |
Convert the rest of test_runners.py to doctests; even though incomplete, they
test everything the old unit tests tested. There are XXX's left in the
doctests as reminders to flesh them out.
Change the NNTP_REWRITE_DUPLICATE_HEADERS to use proper capitalization.
Revert a change I made in the conversion of the Switchboard class:
Switchboard.files is no longer a generator. The Runner implementation is
cleaner if this returns a concrete list, so that's what it does now. Update
the tests to reflect that.
The Runner simplifies now too because it no longer needs _open_files() or the
_listcache WeakValueDictionary. The standard list manager handles all this
now, so just use it directly.
Also change the way the Runner sets the language context in _onefile(). It
still tries to set it to the preferred language of the sender, if the sender
is a member of the list. Otherwise it sets it to the list's preferred
language, not the system's preferred language. Removed a conditional that
can't possibly happen.
Diffstat (limited to 'Mailman/Queue')
| -rw-r--r-- | Mailman/Queue/Runner.py | 29 | ||||
| -rw-r--r-- | Mailman/Queue/Switchboard.py | 3 | ||||
| -rw-r--r-- | Mailman/Queue/tests/test_runners.py | 163 |
3 files changed, 7 insertions, 188 deletions
diff --git a/Mailman/Queue/Runner.py b/Mailman/Queue/Runner.py index 953a201de..33d47ba47 100644 --- a/Mailman/Queue/Runner.py +++ b/Mailman/Queue/Runner.py @@ -86,7 +86,7 @@ class Runner: # Switchboard.files() is guaranteed to hand us the files in FIFO # order. Return an integer count of the number of files that were # available for this qrunner to process. - files = self._switchboard.files() + files = self._switchboard.files for filebase in files: try: # Ask the switchboard for the message and metadata objects @@ -147,7 +147,7 @@ class Runner: # # Find out which mailing list this message is destined for. listname = msgdata.get('listname') - mlist = self._open_list(listname) + mlist = config.list_manager.get(listname) if not mlist: log.error('Dequeuing message destined for missing list: %s', listname) @@ -164,10 +164,11 @@ class Runner: # approach, but I can't think of anything better right now. otranslation = i18n.get_translation() sender = msg.get_sender() - if mlist: - lang = mlist.getMemberLanguage(sender) + member = mlist.members.get_member(sender) + if member: + lang = member.preferred_language else: - lang = config.DEFAULT_SERVER_LANGUAGE + lang = mlist.preferred_language i18n.set_language(lang) msgdata['lang'] = lang try: @@ -181,24 +182,6 @@ class Runner: if keepqueued: self._switchboard.enqueue(msg, msgdata) - # Mapping of listnames to MailList instances as a weak value dictionary. - _listcache = weakref.WeakValueDictionary() - - def _open_list(self, listname): - # Cache the open list so that any use of the list within this process - # uses the same object. We use a WeakValueDictionary so that when the - # list is no longer necessary, its memory is freed. - mlist = self._listcache.get(listname) - if not mlist: - try: - mlist = MailList.MailList(listname, lock=False) - except Errors.MMListError, e: - log.error('error opening list: %s\n%s', listname, e) - return None - else: - self._listcache[listname] = mlist - return mlist - def _log(self, exc): log.error('Uncaught runner exception: %s', exc) s = StringIO() diff --git a/Mailman/Queue/Switchboard.py b/Mailman/Queue/Switchboard.py index 91dfad8c0..2c8672f57 100644 --- a/Mailman/Queue/Switchboard.py +++ b/Mailman/Queue/Switchboard.py @@ -178,8 +178,7 @@ class Switchboard: key += DELTA times[key] = filebase # FIFO sort - for key in sorted(times): - yield times[key] + return [times[key] for key in sorted(times)] def recover_backup_files(self): # Move all .bak files in our slice to .pck. It's impossible for both diff --git a/Mailman/Queue/tests/test_runners.py b/Mailman/Queue/tests/test_runners.py deleted file mode 100644 index 27269909f..000000000 --- a/Mailman/Queue/tests/test_runners.py +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright (C) 2001-2007 by the Free Software Foundation, Inc. -# -# This program 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 2 -# of the License, or (at your option) any later version. -# -# This program 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 this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -# USA. - -"""Unit tests for the various Mailman qrunner modules.""" - -import os -import email -import shutil -import tempfile -import unittest - -from Mailman.Message import Message -from Mailman.Queue.NewsRunner import prepare_message -from Mailman.Queue.Runner import Runner -from Mailman.Queue.Switchboard import Switchboard -from Mailman.testing.base import TestBase - - - -class TestPrepMessage(TestBase): - def test_remove_unacceptables(self): - eq = self.assertEqual - msg = email.message_from_string("""\ -From: aperson@dom.ain -To: _xtest@dom.ain -NNTP-Posting-Host: news.dom.ain -NNTP-Posting-Date: today -X-Trace: blah blah -X-Complaints-To: abuse@dom.ain -Xref: blah blah -Xref: blah blah -Date-Received: yesterday -Posted: tomorrow -Posting-Version: 99.99 -Relay-Version: 88.88 -Received: blah blah - -A message -""") - msgdata = {} - prepare_message(self._mlist, msg, msgdata) - eq(msgdata.get('prepped'), 1) - eq(msg['from'], 'aperson@dom.ain') - eq(msg['to'], '_xtest@dom.ain') - eq(msg['nntp-posting-host'], None) - eq(msg['nntp-posting-date'], None) - eq(msg['x-trace'], None) - eq(msg['x-complaints-to'], None) - eq(msg['xref'], None) - eq(msg['date-received'], None) - eq(msg['posted'], None) - eq(msg['posting-version'], None) - eq(msg['relay-version'], None) - eq(msg['received'], None) - - def test_munge_duplicates_no_duplicates(self): - eq = self.assertEqual - msg = email.message_from_string("""\ -From: aperson@dom.ain -To: _xtest@dom.ain -Cc: someother@dom.ain -Content-Transfer-Encoding: yes - -A message -""") - msgdata = {} - prepare_message(self._mlist, msg, msgdata) - eq(msgdata.get('prepped'), 1) - eq(msg['from'], 'aperson@dom.ain') - eq(msg['to'], '_xtest@dom.ain') - eq(msg['cc'], 'someother@dom.ain') - eq(msg['content-transfer-encoding'], 'yes') - - def test_munge_duplicates(self): - eq = self.assertEqual - msg = email.message_from_string("""\ -From: aperson@dom.ain -To: _xtest@dom.ain -To: two@dom.ain -Cc: three@dom.ain -Cc: four@dom.ain -Cc: five@dom.ain -Content-Transfer-Encoding: yes -Content-Transfer-Encoding: no -Content-Transfer-Encoding: maybe - -A message -""") - msgdata = {} - prepare_message(self._mlist, msg, msgdata) - eq(msgdata.get('prepped'), 1) - eq(msg.get_all('from'), ['aperson@dom.ain']) - eq(msg.get_all('to'), ['_xtest@dom.ain']) - eq(msg.get_all('cc'), ['three@dom.ain']) - eq(msg.get_all('content-transfer-encoding'), ['yes']) - eq(msg.get_all('x-original-to'), ['two@dom.ain']) - eq(msg.get_all('x-original-cc'), ['four@dom.ain', 'five@dom.ain']) - eq(msg.get_all('x-original-content-transfer-encoding'), - ['no', 'maybe']) - - - -class TestableRunner(Runner): - def _dispose(self, mlist, msg, msgdata): - self.msg = msg - self.data = msgdata - return False - - def _doperiodic(self): - self.stop() - - def _snooze(self, filecnt): - return - - -class TestRunner(TestBase): - def setUp(self): - TestBase.setUp(self) - self._tmpdir = tempfile.mkdtemp() - self._msg = email.message_from_string("""\ -From: aperson@dom.ain -To: _xtest@dom.ain - -A test message. -""", Message) - class MyRunner(TestableRunner): - QDIR = self._tmpdir - self._runner = MyRunner() - - def tearDown(self): - shutil.rmtree(self._tmpdir, True) - TestBase.tearDown(self) - - def test_run_loop(self): - eq = self.assertEqual - sb = Switchboard(self._tmpdir) - sb.enqueue(self._msg, listname='_xtest@example.com', foo='yes') - self._runner.run() - eq(self._runner.msg['from'], self._msg['from']) - eq(self._runner.msg['to'], self._msg['to']) - eq(self._runner.data['foo'], 'yes') - - - -def test_suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestPrepMessage)) - suite.addTest(unittest.makeSuite(TestRunner)) - return suite |
