summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2009-05-27 17:44:10 +0200
committerBarry Warsaw2009-05-27 17:44:10 +0200
commit4cf56226a52d2f5e607b5d4d83e20ae24619a383 (patch)
tree6ad22c2fa9b74f40bb5403a5e1357715afc861c4
parentcdd4885e9fe6eb074022421433d9be9abf3415b4 (diff)
downloadmailman-4cf56226a52d2f5e607b5d4d83e20ae24619a383.tar.gz
mailman-4cf56226a52d2f5e607b5d4d83e20ae24619a383.tar.zst
mailman-4cf56226a52d2f5e607b5d4d83e20ae24619a383.zip
-rw-r--r--src/mailman/rest/docs/__init__.py30
-rw-r--r--src/mailman/rest/docs/basic.txt13
-rw-r--r--src/mailman/testing/layers.py21
-rw-r--r--src/mailman/tests/test_documentation.py20
4 files changed, 68 insertions, 16 deletions
diff --git a/src/mailman/rest/docs/__init__.py b/src/mailman/rest/docs/__init__.py
new file mode 100644
index 000000000..680ff5b47
--- /dev/null
+++ b/src/mailman/rest/docs/__init__.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2009 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 <http://www.gnu.org/licenses/>.
+
+"""Doctest layer setup."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'layer',
+ ]
+
+
+
+from mailman.testing.layers import RESTLayer
+layer = RESTLayer
diff --git a/src/mailman/rest/docs/basic.txt b/src/mailman/rest/docs/basic.txt
index 40934ec1f..490db6d11 100644
--- a/src/mailman/rest/docs/basic.txt
+++ b/src/mailman/rest/docs/basic.txt
@@ -1,12 +1,9 @@
+===========
REST server
===========
Mailman exposes a REST HTTP server for administrative control.
- >>> from mailman.rest.testing.server import TestableServer
- >>> server = TestableServer()
- >>> server.start()
-
The server listens for connections on a configurable host name and port.
Because the REST server has full administrative access, it should always be
run only on localhost, unless you really know what you're doing. The Mailman
@@ -24,7 +21,7 @@ returned.
Non-existent links
-------------------
+==================
when you try to access an admin link that doesn't exist, you get the
appropriate HTTP 404 Not Found error.
@@ -34,9 +31,3 @@ appropriate HTTP 404 Not Found error.
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found
-
-
-Cleanup
--------
-
- >>> server.stop()
diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py
index 3f7e63406..9e4364a7a 100644
--- a/src/mailman/testing/layers.py
+++ b/src/mailman/testing/layers.py
@@ -23,6 +23,7 @@ __metaclass__ = type
__all__ = [
'ConfigLayer',
'MockAndMonkeyLayer',
+ 'RESTLayer',
'SMTPLayer',
]
@@ -221,3 +222,23 @@ class SMTPLayer(ConfigLayer):
@classmethod
def testTearDown(cls):
pass
+
+
+
+class RESTLayer(SMTPLayer):
+ """Layer for starting, stopping, and accessing the test REST layer."""
+
+ server = None
+
+ @classmethod
+ def setUp(cls):
+ assert cls.server is None, 'Layer already set up'
+ from mailman.rest.testing.server import TestableServer
+ cls.server = TestableServer()
+ cls.server.start()
+
+ @classmethod
+ def tearDown(cls):
+ assert cls.server is not None, 'Layer not set up'
+ cls.server.stop()
+ cls.server = None
diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/tests/test_documentation.py
index d1ff75275..0c061e873 100644
--- a/src/mailman/tests/test_documentation.py
+++ b/src/mailman/tests/test_documentation.py
@@ -30,6 +30,7 @@ __all__ = [
import os
+import sys
import json
import random
import doctest
@@ -156,17 +157,26 @@ def test_suite():
doctest_files = {}
with chdir(topdir):
for docsdir in packages:
+ # Look to see if the package defines a test layer, otherwise use
+ # SMTPLayer.
+ package_path = 'mailman.' + DOT.join(docsdir.split(os.sep))
+ try:
+ __import__(package_path)
+ except ImportError:
+ layer = SMTPLayer
+ else:
+ layer = getattr(sys.modules[package_path], 'layer', SMTPLayer)
for filename in os.listdir(docsdir):
if os.path.splitext(filename)[1] == '.txt':
- doctest_files[filename] = os.path.join(docsdir, filename)
- files = sorted(doctest_files)
- for filename in files:
- path = doctest_files[filename]
+ doctest_files[filename] = (
+ os.path.join(docsdir, filename), layer)
+ for filename in sorted(doctest_files):
+ path, layer = doctest_files[filename]
test = doctest.DocFileSuite(
path,
package='mailman',
optionflags=flags,
setUp=setup)
- test.layer = SMTPLayer
+ test.layer = layer
suite.addTest(test)
return suite