summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/runners/docs/nntp.rst136
-rw-r--r--src/mailman/testing/helpers.py20
-rw-r--r--src/mailman/tests/test_documentation.py11
3 files changed, 47 insertions, 120 deletions
diff --git a/src/mailman/runners/docs/nntp.rst b/src/mailman/runners/docs/nntp.rst
index c54dd3696..31c7210cf 100644
--- a/src/mailman/runners/docs/nntp.rst
+++ b/src/mailman/runners/docs/nntp.rst
@@ -7,10 +7,14 @@ The NNTP runner gateways mailing list messages to an NNTP newsgroup.
>>> mlist = create_list('test@example.com')
>>> mlist.linked_newsgroup = 'comp.lang.python'
-Some NNTP servers such as INN reject messages containing a set of prohibited
-headers, so one of the things that this runner does is remove these prohibited
-headers.
-::
+Get a handle on the NNTP server, which we'll use later to verify the posted
+messages.
+
+ >>> from mailman.testing.helpers import get_nntp_server
+ >>> nntpd = get_nntp_server(cleanups)
+
+A message gets posted to the mailing list. It may contain some headers which
+are prohibited by NNTP servers such as INN.
>>> msg = message_from_string("""\
... From: aperson@example.com
@@ -29,130 +33,24 @@ headers.
...
... A message
... """)
- >>> msgdata = {}
-
- >>> from mailman.runners.nntp import prepare_message
- >>> prepare_message(mlist, msg, msgdata)
- >>> msgdata['prepped']
- True
- >>> print msg.as_string()
- From: aperson@example.com
- To: test@example.com
- Newsgroups: comp.lang.python
- Message-ID: ...
- Lines: 1
- <BLANKLINE>
- A message
- <BLANKLINE>
-Some NNTP servers will reject messages where certain headers are duplicated,
-so the news runner must collapse or move these duplicate headers to an
-``X-Original-*`` header that the news server doesn't care about.
+The message gets copied to the NNTP queue for preparation and posting.
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: test@example.com
- ... To: two@example.com
- ... Cc: three@example.com
- ... Cc: four@example.com
- ... Cc: five@example.com
- ... Content-Transfer-Encoding: yes
- ... Content-Transfer-Encoding: no
- ... Content-Transfer-Encoding: maybe
- ...
- ... A message
- ... """)
- >>> msgdata = {}
- >>> prepare_message(mlist, msg, msgdata)
- >>> msgdata['prepped']
- True
- >>> print msg.as_string()
- From: aperson@example.com
- Newsgroups: comp.lang.python
- Message-ID: ...
- Lines: 1
- To: test@example.com
- X-Original-To: two@example.com
- CC: three@example.com
- X-Original-CC: four@example.com
- X-Original-CC: five@example.com
- Content-Transfer-Encoding: yes
- X-Original-Content-Transfer-Encoding: no
- X-Original-Content-Transfer-Encoding: maybe
- <BLANKLINE>
- A message
- <BLANKLINE>
+ >>> filebase = config.switchboards['nntp'].enqueue(
+ ... msg, listname='test@example.com')
+ >>> from mailman.testing.helpers import make_testable_runner
+ >>> from mailman.runners.nntp import NNTPRunner
+ >>> runner = make_testable_runner(NNTPRunner, 'nntp')
+ >>> runner.run()
-But if no headers are duplicated, then the news runner doesn't need to modify
-the message.
+The message was successfully posted the NNTP server.
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: test@example.com
- ... Cc: someother@example.com
- ... Content-Transfer-Encoding: yes
- ...
- ... A message
- ... """)
- >>> msgdata = {}
- >>> prepare_message(mlist, msg, msgdata)
- >>> msgdata['prepped']
- True
- >>> print msg.as_string()
+ >>> print nntpd.get_message().as_string()
From: aperson@example.com
To: test@example.com
- Cc: someother@example.com
- Content-Transfer-Encoding: yes
Newsgroups: comp.lang.python
Message-ID: ...
Lines: 1
<BLANKLINE>
A message
<BLANKLINE>
-
-
-Newsgroup moderation
-====================
-
-When the newsgroup is moderated, an ``Approved:`` header with the list's
-posting address is added for the benefit of the Usenet system.
-::
-
- >>> from mailman.interfaces.nntp import NewsModeration
- >>> mlist.news_moderation = NewsModeration.open_moderated
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: test@example.com
- ... Approved: this gets deleted
- ...
- ... """)
- >>> prepare_message(mlist, msg, {})
- >>> print msg['approved']
- test@example.com
-
- >>> mlist.news_moderation = NewsModeration.moderated
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: test@example.com
- ... Approved: this gets deleted
- ...
- ... """)
- >>> prepare_message(mlist, msg, {})
- >>> print msg['approved']
- test@example.com
-
-But if the newsgroup is not moderated, the ``Approved:`` header is not changed.
-
- >>> mlist.news_moderation = NewsModeration.none
- >>> msg = message_from_string("""\
- ... From: aperson@example.com
- ... To: test@example.com
- ... Approved: this doesn't get deleted
- ...
- ... """)
- >>> prepare_message(mlist, msg, {})
- >>> msg['approved']
- u"this doesn't get deleted"
-
-
-XXX More of the NewsRunner should be tested.
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
@@ -253,6 +255,24 @@ def get_lmtp_client(quiet=False):
+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."""
until = datetime.datetime.now() + as_timedelta(config.devmode.wait)
diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/tests/test_documentation.py
index f459f3a92..a2c1ab592 100644
--- a/src/mailman/tests/test_documentation.py
+++ b/src/mailman/tests/test_documentation.py
@@ -178,6 +178,14 @@ def setup(testobj):
testobj.globs['smtpd'] = SMTPLayer.smtpd
testobj.globs['stop'] = stop
testobj.globs['transaction'] = config.db
+ # Add this so that cleanups can be automatically added by the doctest.
+ testobj.globs['cleanups'] = []
+
+
+
+def teardown(testobj):
+ for cleanup in testobj.globs['cleanups']:
+ cleanup()
@@ -223,7 +231,8 @@ def test_suite():
path,
package='mailman',
optionflags=flags,
- setUp=setup)
+ setUp=setup,
+ tearDown=teardown)
test.layer = layer
suite.addTest(test)
return suite