summaryrefslogtreecommitdiff
path: root/src/mailman/testing/helpers.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-08 10:15:29 -0600
committerBarry Warsaw2012-04-08 10:15:29 -0600
commit2410fe8c2578fbd11275cfc7fc1897173eecd41a (patch)
tree77d5e612f2efd1844bb777102067f3f658aa499c /src/mailman/testing/helpers.py
parent7abcd4faa1553fb012020b6204fb8b6208fa5bf2 (diff)
downloadmailman-2410fe8c2578fbd11275cfc7fc1897173eecd41a.tar.gz
mailman-2410fe8c2578fbd11275cfc7fc1897173eecd41a.tar.zst
mailman-2410fe8c2578fbd11275cfc7fc1897173eecd41a.zip
- Refactor the way databases are schema-migrated so that load_migrations()
can be tested separately. - Add an `until` argument to load_migrations() so that we can load only up to a given timestamp. - In load_migrations(), ignore files in which the `version` part of the file name is empty. - In migrations.rst, use the new, better way of ensuring post-test cleanup. - Add tests for partial upgrades. - LP: #971013 - schema migrations for beta 2. - LP: #967238 - IMailingList.archive + IMailingList.archive_private -> IMailingList.archive_policy, and add ArchivePolicy enum. - Move the `chdir` context manager to helpers.py and add `temporary_db` context manager.
Diffstat (limited to 'src/mailman/testing/helpers.py')
-rw-r--r--src/mailman/testing/helpers.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index 3648a6710..d9885cbac 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -25,6 +25,7 @@ __all__ = [
'TestableMaster',
'body_line_iterator',
'call_api',
+ 'chdir',
'configuration',
'digest_mbox',
'event_subscribers',
@@ -35,6 +36,7 @@ __all__ = [
'reset_the_world',
'specialized_message_from_string',
'subscribe',
+ 'temporary_db',
'wait_for_webservice',
]
@@ -392,6 +394,34 @@ class configuration:
+@contextmanager
+def temporary_db(db):
+ real_db = config.db
+ config.db = db
+ try:
+ yield
+ finally:
+ config.db = real_db
+
+
+
+class chdir:
+ """A context manager for temporary directory changing."""
+ def __init__(self, directory):
+ self._curdir = None
+ self._directory = directory
+
+ def __enter__(self):
+ self._curdir = os.getcwd()
+ os.chdir(self._directory)
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ os.chdir(self._curdir)
+ # Don't suppress exceptions.
+ return False
+
+
+
def subscribe(mlist, first_name, role=MemberRole.member):
"""Helper for subscribing a sample person to a mailing list."""
user_manager = getUtility(IUserManager)