diff options
Diffstat (limited to 'src/mailman/testing')
| -rw-r--r-- | src/mailman/testing/helpers.py | 5 | ||||
| -rw-r--r-- | src/mailman/testing/layers.py | 35 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index e61aca605..58c72d6d9 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -223,7 +223,7 @@ class LMTP(smtplib.SMTP): return code, msg -def get_lmtp_client(): +def get_lmtp_client(quiet=False): """Return a connected LMTP client.""" # It's possible the process has started but is not yet accepting # connections. Wait a little while. @@ -233,7 +233,8 @@ def get_lmtp_client(): try: response = lmtp.connect( config.mta.lmtp_host, int(config.mta.lmtp_port)) - print response + if not quiet: + print response return lmtp except socket.error as error: if error[0] == errno.ECONNREFUSED: diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index 5cee8c8d2..04ab8f91f 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ 'ConfigLayer', + 'LMTPLayer', 'MockAndMonkeyLayer', 'RESTLayer', 'SMTPLayer', @@ -48,7 +49,8 @@ from mailman.core import initialize from mailman.core.initialize import INHIBIT_CONFIG_FILE from mailman.core.logging import get_handler from mailman.interfaces.domain import IDomainManager -from mailman.testing.helpers import TestableMaster, reset_the_world +from mailman.testing.helpers import ( + TestableMaster, get_lmtp_client, reset_the_world) from mailman.testing.mta import ConnectionCountingController from mailman.utilities.string import expand @@ -250,6 +252,8 @@ class SMTPLayer(ConfigLayer): @classmethod def testSetUp(cls): + # Make sure we don't call our superclass's testSetUp(), otherwise the + # example.com domain will get added twice. pass @classmethod @@ -259,6 +263,35 @@ class SMTPLayer(ConfigLayer): +class LMTPLayer(ConfigLayer): + """Layer for starting, stopping, and accessing a test LMTP server.""" + + lmtpd = None + + @staticmethod + def _wait_for_lmtp_server(): + get_lmtp_client(quiet=True) + + @classmethod + def setUp(cls): + assert cls.lmtpd is None, 'Layer already set up' + cls.lmtpd = TestableMaster(cls._wait_for_lmtp_server) + cls.lmtpd.start('lmtp') + + @classmethod + def tearDown(cls): + assert cls.lmtpd is not None, 'Layer not set up' + cls.lmtpd.stop() + cls.lmtpd = None + + @classmethod + def testSetUp(cls): + # Make sure we don't call our superclass's testSetUp(), otherwise the + # example.com domain will get added twice. + pass + + + class RESTLayer(SMTPLayer): """Layer for starting, stopping, and accessing the test REST layer.""" |
