summaryrefslogtreecommitdiff
path: root/src/mailman/testing/helpers.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-07-06 21:08:41 -0400
committerBarry Warsaw2012-07-06 21:08:41 -0400
commit8d8ab1655b51e277570005b445d3b014afcfbc57 (patch)
tree6ba0147d975636e129a787c9dfa64dae8cffae89 /src/mailman/testing/helpers.py
parentcd3f84b301c2150fea5402129a2e7bc862fbb52b (diff)
parent01415190ab44e69a8f09a6411564a7cb288404e8 (diff)
downloadmailman-8d8ab1655b51e277570005b445d3b014afcfbc57.tar.gz
mailman-8d8ab1655b51e277570005b445d3b014afcfbc57.tar.zst
mailman-8d8ab1655b51e277570005b445d3b014afcfbc57.zip
Diffstat (limited to 'src/mailman/testing/helpers.py')
-rw-r--r--src/mailman/testing/helpers.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index d9885cbac..054dd4ff7 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -17,7 +17,7 @@
"""Various test helpers."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -66,6 +66,7 @@ from zope.component import getUtility
from mailman.bin.master import Loop as Master
from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.email.message import Message
from mailman.interfaces.member import MemberRole
from mailman.interfaces.messages import IMessageStore
@@ -239,13 +240,14 @@ def get_lmtp_client(quiet=False):
# It's possible the process has started but is not yet accepting
# connections. Wait a little while.
lmtp = LMTP()
+ #lmtp.debuglevel = 1
until = datetime.datetime.now() + as_timedelta(config.devmode.wait)
while datetime.datetime.now() < until:
try:
response = lmtp.connect(
config.mta.lmtp_host, int(config.mta.lmtp_port))
if not quiet:
- print response
+ print(response)
return lmtp
except socket.error as error:
if error[0] == errno.ECONNREFUSED:
@@ -343,14 +345,14 @@ def call_api(url, data=None, method=None, username=None, password=None):
@contextmanager
def event_subscribers(*subscribers):
- """Temporarily set the Zope event subscribers list.
+ """Temporarily extend the Zope event subscribers list.
:param subscribers: A sequence of event subscribers.
:type subscribers: sequence of callables, each receiving one argument, the
event.
"""
old_subscribers = event.subscribers[:]
- event.subscribers = list(subscribers)
+ event.subscribers.extend(subscribers)
try:
yield
finally:
@@ -363,8 +365,14 @@ class configuration:
def __init__(self, section, **kws):
self._section = section
+ # Most tests don't care about the name given to the temporary
+ # configuration. Usually we'll just craft a random one, but some
+ # tests do care, so give them a hook to set it.
+ if '_configname' in kws:
+ self._uuid = kws.pop('_configname')
+ else:
+ self._uuid = uuid.uuid4().hex
self._values = kws.copy()
- self._uuid = uuid.uuid4().hex
def _apply(self):
lines = ['[{0}]'.format(self._section)]
@@ -427,19 +435,19 @@ def subscribe(mlist, first_name, role=MemberRole.member):
user_manager = getUtility(IUserManager)
email = '{0}person@example.com'.format(first_name[0].lower())
full_name = '{0} Person'.format(first_name)
- person = user_manager.get_user(email)
- if person is None:
- address = user_manager.get_address(email)
- if address is None:
- person = user_manager.create_user(email, full_name)
+ with transaction():
+ person = user_manager.get_user(email)
+ if person is None:
+ address = user_manager.get_address(email)
+ if address is None:
+ person = user_manager.create_user(email, full_name)
+ preferred_address = list(person.addresses)[0]
+ mlist.subscribe(preferred_address, role)
+ else:
+ mlist.subscribe(address, role)
+ else:
preferred_address = list(person.addresses)[0]
mlist.subscribe(preferred_address, role)
- else:
- mlist.subscribe(address, role)
- else:
- preferred_address = list(person.addresses)[0]
- mlist.subscribe(preferred_address, role)
- config.db.commit()
@@ -467,9 +475,9 @@ def reset_the_world():
os.remove(os.path.join(dirpath, filename))
# Clear out messages in the message store.
message_store = getUtility(IMessageStore)
- for message in message_store.messages:
- message_store.delete_message(message['message-id'])
- config.db.commit()
+ with transaction():
+ for message in message_store.messages:
+ message_store.delete_message(message['message-id'])
# Reset the global style manager.
getUtility(IStyleManager).populate()
# Remove all dynamic header-match rules.