summaryrefslogtreecommitdiff
path: root/mailman/tests
diff options
context:
space:
mode:
authorBarry Warsaw2008-03-27 05:14:14 -0400
committerBarry Warsaw2008-03-27 05:14:14 -0400
commit17f286de64cb3373d68c4fefba6d9369b4e3f960 (patch)
tree5078531044f0574dfa340a389bd6d0bb9eea717f /mailman/tests
parentde9deb660c5d48a083f0c56916cca6aa0cb010b3 (diff)
downloadmailman-17f286de64cb3373d68c4fefba6d9369b4e3f960.tar.gz
mailman-17f286de64cb3373d68c4fefba6d9369b4e3f960.tar.zst
mailman-17f286de64cb3373d68c4fefba6d9369b4e3f960.zip
Added a test of the OutgoingRunner, and subsequent changes to make it pass,
including: - MailingList.full_path -> IMailingList.data_path and implement this as a property on the MailingList object. - Fix the 'decorate' handler to work with the new member/user data model, instead of the old MemberAdaptor interface. - Fix a few problems with the smtp-direct handler, though this needs more work and tests. - Add some debug logging to both the test smtplistener and the SMTPServer proxy. Fix the proxy's consumption of messages from the thread queue. - Fix the smtplistener's calculation of the X-Peer header.
Diffstat (limited to 'mailman/tests')
-rw-r--r--mailman/tests/helpers.py17
-rw-r--r--mailman/tests/smtplistener.py7
2 files changed, 19 insertions, 5 deletions
diff --git a/mailman/tests/helpers.py b/mailman/tests/helpers.py
index 71b3ff60e..d1eda9e34 100644
--- a/mailman/tests/helpers.py
+++ b/mailman/tests/helpers.py
@@ -34,6 +34,7 @@ import time
import errno
import signal
import socket
+import logging
import mailbox
import smtplib
import tempfile
@@ -48,6 +49,9 @@ from mailman.queue import Switchboard
from mailman.tests.smtplistener import Server
+log = logging.getLogger('mailman.debug')
+
+
def make_testable_runner(runner_class):
"""Create a queue runner that runs until its queue is empty.
@@ -97,7 +101,7 @@ def digest_mbox(mlist):
:param mlist: The mailing list.
:return: The mailing list's pending digest as a mailbox.
"""
- path = os.path.join(mlist.full_path, 'digest.mbox')
+ path = os.path.join(mlist.data_path, 'digest.mbox')
return mailbox.mbox(path)
@@ -168,6 +172,7 @@ class SMTPServer:
def start(self):
"""Start the smtp server in a thread."""
+ log.info('test SMTP server starting')
self._thread.start()
def stop(self):
@@ -178,18 +183,22 @@ class SMTPServer:
self.clear()
# Wait for the thread to exit.
self._thread.join()
+ log.info('test SMTP server stopped')
@property
def messages(self):
"""Return all the messages received by the smtp server."""
- for message in self._messages:
- # See if there's anything waiting in the queue.
+ # Look at the thread queue and append any messages from there to our
+ # internal list of messages.
+ while True:
try:
message = self._queue.get_nowait()
except Empty:
- pass
+ break
else:
self._messages.append(message)
+ # Now return all the messages we know about.
+ for message in self._messages:
yield message
def clear(self):
diff --git a/mailman/tests/smtplistener.py b/mailman/tests/smtplistener.py
index 3a5b870b7..1dc11e3e0 100644
--- a/mailman/tests/smtplistener.py
+++ b/mailman/tests/smtplistener.py
@@ -18,11 +18,14 @@
"""A test SMTP listener."""
import smtpd
+import logging
import asyncore
from email import message_from_string
+
COMMASPACE = ', '
+log = logging.getLogger('mailman.debug')
@@ -60,14 +63,16 @@ class Server(smtpd.SMTPServer):
def handle_accept(self):
"""Handle connections by creating our own Channel object."""
conn, addr = self.accept()
+ log.info('accepted: %s', addr)
Channel(self, conn, addr)
def process_message(self, peer, mailfrom, rcpttos, data):
"""Process a message by adding it to the mailbox."""
message = message_from_string(data)
- message['X-Peer'] = peer
+ message['X-Peer'] = '%s:%s' % peer
message['X-MailFrom'] = mailfrom
message['X-RcptTo'] = COMMASPACE.join(rcpttos)
+ log.info('processed message: %s', message.get('message-id', 'n/a'))
self._queue.put(message)
def start(self):