diff options
| author | Barry Warsaw | 2010-06-18 19:23:35 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2010-06-18 19:23:35 -0400 |
| commit | b3e874703bce97c121eb97dd9776da15a8b90070 (patch) | |
| tree | 9d884eeb4c6fd4a5e7aad8e96ced642f57ecc7ac /src/mailman/testing | |
| parent | f4e7637b1682f025cc6c8bfb172eda8b710e3218 (diff) | |
| download | mailman-b3e874703bce97c121eb97dd9776da15a8b90070.tar.gz mailman-b3e874703bce97c121eb97dd9776da15a8b90070.tar.zst mailman-b3e874703bce97c121eb97dd9776da15a8b90070.zip | |
* Fix the bin/test -e/--stderr option to work with the current
zope.testrunner. Actually, divorce it from the latter and handle the
sys.argv sequence ourselves.
* Added IMailingList.get_roster() which returns the named roster (from a
MemberRole enum).
* The start of an IMailingList doctest. This needs much more detail.
* Move the subscribe() function from membership.txt into the
mailman.testing.helpers.
* Added new REST interface for getting all the members of a roster for a
specific mailing list: .../lists/<list>/roster/<role>. Note that <role> is
the plural form of the MemberRole enum.
Diffstat (limited to 'src/mailman/testing')
| -rw-r--r-- | src/mailman/testing/helpers.py | 18 | ||||
| -rw-r--r-- | src/mailman/testing/layers.py | 29 |
2 files changed, 34 insertions, 13 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index b9936ac71..67e2ad21a 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -27,6 +27,7 @@ __all__ = [ 'get_lmtp_client', 'get_queue_messages', 'make_testable_runner', + 'subscribe', 'wait_for_webservice', ] @@ -43,9 +44,12 @@ import threading from contextlib import contextmanager from zope import event +from zope.component import getUtility from mailman.bin.master import Loop as Master from mailman.config import config +from mailman.interfaces.member import MemberRole +from mailman.interfaces.usermanager import IUserManager from mailman.utilities.mailbox import Mailbox @@ -252,3 +256,17 @@ def event_subscribers(*subscribers): event.subscribers = list(subscribers) yield event.subscribers[:] = old_subscribers + + + +def subscribe(mlist, first_name, role=MemberRole.member): + """Helper for subscribing a sample person to a mailing list.""" + user_manager = getUtility(IUserManager) + address = '{0}person@example.com'.format(first_name[0].lower()) + full_name = '{0} Person'.format(first_name) + person = user_manager.get_user(address) + if person is None: + person = user_manager.create_user(address, full_name) + preferred_address = list(person.addresses)[0] + preferred_address.subscribe(mlist, role) + config.db.commit() diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index e7907b172..34dc46807 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -197,22 +197,25 @@ class ConfigLayer(MockAndMonkeyLayer): stderr = False @classmethod - def handle_stderr(cls, *ignore): - cls.stderr = True + def enable_stderr(cls): + """Enable stderr logging if -e/--stderr is given. - @classmethod - def hack_options_parser(cls): - """Hack our way into the zc.testing framework. + We used to hack our way into the zc.testing framework, but that was + undocumented and way too fragile. Well, this probably is too, but now + we just scan sys.argv for -e/--stderr and enable logging if found. + Then we remove the option from sys.argv. This works because this + method is called before zope.testrunner sees the options. - Add our custom command line option parsing into zc.testing's. We do - the imports here so that if zc.testing isn't invoked, this stuff never - gets in the way. This is pretty fragile, depend on changes in the - zc.testing package. There should be a better way! + As a bonus, we'll check an environment variable too. """ - from zope.testing.testrunner.options import parser - parser.add_option(str('-e'), str('--stderr'), - action='callback', callback=cls.handle_stderr, - help=_('Propagate log errors to stderr.')) + if '-e' in sys.argv: + cls.stderr = True + sys.argv.remove('-e') + if '--stderr' in sys.argv: + cls.stderr = True + sys.argv.remove('--stderr') + if len(os.environ.get('MM_VERBOSE_TESTLOG', '').strip()) > 0: + cls.stderr = True |
