From 5598b9eea196e4085aa91aaf8a0cacaffa200355 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 23 Jul 2012 10:40:53 -0400 Subject: Checkpointing Postgres port of test suite. - Refactor load_schema() into a separate load_sql() method. - Add API for test suite to make a temporary database. - Add code to migrate the PostgreSQL database. - Comment out `moderation_callback` from the PostgreSQL SQL; this must have snuck in accidentally via the contributed port. - Refactor test_migrations.py --- src/mailman/database/postgresql.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/mailman/database/postgresql.py') diff --git a/src/mailman/database/postgresql.py b/src/mailman/database/postgresql.py index 988f7a1af..14855c3f3 100644 --- a/src/mailman/database/postgresql.py +++ b/src/mailman/database/postgresql.py @@ -26,10 +26,23 @@ __all__ = [ from operator import attrgetter +from urlparse import urlsplit, urlunsplit +from mailman.config import config from mailman.database.base import StormBaseDatabase + + +class _TemporaryDB: + def __init__(self, database): + self.database = database + + def cleanup(self): + self.database.execute('ROLLBACK TO SAVEPOINT testing;') + self.database.execute('DROP DATABASE mmtest;') + + class PostgreSQLDatabase(StormBaseDatabase): """Database class for PostgreSQL.""" @@ -40,8 +53,8 @@ class PostgreSQLDatabase(StormBaseDatabase): """See `BaseDatabase`.""" table_query = ('SELECT table_name FROM information_schema.tables ' "WHERE table_schema = 'public'") - table_names = set(item[0] for item in - store.execute(table_query)) + results = store.execute(table_query) + table_names = set(item[0] for item in results) return 'version' in table_names def _post_reset(self, store): @@ -63,3 +76,18 @@ class PostgreSQLDatabase(StormBaseDatabase): max("id") IS NOT null) FROM "{0}"; """.format(model_class.__storm_table__)) + + @staticmethod + def _make_temporary(): + from mailman.testing.helpers import configuration + parts = urlsplit(config.database.url) + assert parts.scheme == 'postgres' + new_parts = list(parts) + new_parts[2] = '/mmtest' + url = urlunsplit(new_parts) + database = PostgreSQLDatabase() + database.store.execute('SAVEPOINT testing;') + database.store.execute('CREATE DATABASE mmtest;') + with configuration('database', url=url): + database.initialize() + return _TemporaryDB(database) -- cgit v1.2.3-70-g09d2