From 2c4779c884d2bb09bed6838b7b5cd938d5755f2e Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 2 Apr 2012 13:07:21 -0600 Subject: - Improve the NNTP doctest. - Add a `cleanups` global to doctests. This can be used to register functions which will get called automatically at doctest tearDown time. --- src/mailman/testing/helpers.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/mailman/testing/helpers.py') diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index ca0b14b18..8295ef3a8 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -29,6 +29,7 @@ __all__ = [ 'digest_mbox', 'event_subscribers', 'get_lmtp_client', + 'get_nntp_server', 'get_queue_messages', 'make_testable_runner', 'reset_the_world', @@ -40,6 +41,7 @@ __all__ = [ import os import json +import mock import time import uuid import errno @@ -252,6 +254,24 @@ def get_lmtp_client(quiet=False): raise RuntimeError('Connection refused') + +def get_nntp_server(cleanups): + """Create and start an NNTP server mock. + + This can be used to retrieve the posted message for verification. + """ + patcher = mock.patch('nntplib.NNTP') + server_class = patcher.start() + cleanups.append(patcher.stop) + nntpd = server_class() + # A class for more convenient access to the posted message. + class NNTPProxy: + def get_message(self): + args = nntpd.post.call_args + return specialized_message_from_string(args[0][0].read()) + return NNTPProxy() + + def wait_for_webservice(): """Wait for the REST server to start serving requests.""" -- cgit v1.2.3-70-g09d2