summaryrefslogtreecommitdiff
path: root/src/mailman/testing/mta.py
diff options
context:
space:
mode:
authorBarry Warsaw2009-10-31 15:14:37 -0400
committerBarry Warsaw2009-10-31 15:14:37 -0400
commit6ec26d074d923fa83b65b96c4904459d777781f9 (patch)
tree50258e956bc1a7f4eaaa989a34180ebecd3a0de1 /src/mailman/testing/mta.py
parentcac646019303ffe85cfac4c00eca7d44f634a03d (diff)
downloadmailman-6ec26d074d923fa83b65b96c4904459d777781f9.tar.gz
mailman-6ec26d074d923fa83b65b96c4904459d777781f9.tar.zst
mailman-6ec26d074d923fa83b65b96c4904459d777781f9.zip
Diffstat (limited to 'src/mailman/testing/mta.py')
-rw-r--r--src/mailman/testing/mta.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/mailman/testing/mta.py b/src/mailman/testing/mta.py
index 81852a24b..d16b9f955 100644
--- a/src/mailman/testing/mta.py
+++ b/src/mailman/testing/mta.py
@@ -66,13 +66,25 @@ class StatisticsChannel(Channel):
def smtp_RCPT(self, arg):
"""For testing, sometimes cause a non-25x response."""
- if self._server.next_error == 'rcpt':
+ code = self._server.next_error('rcpt')
+ if code is None:
+ # Everything's cool.
+ Channel.smtp_RCPT(self, arg)
+ else:
# The test suite wants this to fail. The message corresponds to
# the exception we expect smtplib.SMTP to raise.
- self.push(b'500 Error: SMTPRecipientsRefused')
- else:
+ self.push(b'%d Error: SMTPRecipientsRefused' % code)
+
+ def smtp_MAIL(self, arg):
+ """For testing, sometimes cause a non-25x response."""
+ code = self._server.next_error('mail')
+ if code is None:
# Everything's cool.
- Channel.smtp_RCPT(self, arg)
+ Channel.smtp_MAIL(self, arg)
+ else:
+ # The test suite wants this to fail. The message corresponds to
+ # the exception we expect smtplib.SMTP to raise.
+ self.push(b'%d Error: SMTPResponseException' % code)
@@ -95,18 +107,32 @@ class ConnectionCountingServer(QueueServer):
# controller upon request.
self._oob_queue = oob_queue
self._err_queue = err_queue
+ self._last_error = None
- @property
- def next_error(self):
- """Return the next error, or None if nothing's on the stack.
+ def next_error(self, command):
+ """Return the next error for the SMTP command, if there is one.
- :return: The next SMTP command that should error.
- :rtype: string (lower cased) or None
+ :param command: The SMTP command for which an error might be
+ expected. If the next error matches the given command, the
+ expected error code is returned.
+ :type command: string, lower-cased
+ :return: An SMTP error code
+ :rtype: integer
"""
- try:
- return self._err_queue.get_nowait()
- except Empty:
- return None
+ # If the last error we pulled from the queue didn't match, then we're
+ # caching it, and it might match this expected error. If there is no
+ # last error in the cache, get one from the queue now.
+ if self._last_error is None:
+ try:
+ self._last_error = self._err_queue.get_nowait()
+ except Empty:
+ # No error is expected
+ return None
+ if self._last_error[0] == command:
+ code = self._last_error[1]
+ self._last_error = None
+ return code
+ return None
def handle_accept(self):
"""See `lazr.smtp.server.Server`."""