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/base.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/mailman/database/base.py') diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index 80c62658e..f674c9a16 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -186,6 +186,22 @@ class StormBaseDatabase: continue upgrade(self, self.store, version, module_path) + def load_sql(self, store, sql): + """Load the given SQL into the store. + + :param store: The Storm store to load the schema into. + :type store: storm.locals.Store` + :param sql: The possibly multi-line SQL to load. + :type sql: string + """ + # Discard all blank and comment lines. + lines = (line for line in sql.splitlines() + if line.strip() != '' and line.strip()[:2] != '--') + sql = NL.join(lines) + for statement in sql.split(';'): + if statement.strip() != '': + store.execute(statement + ';') + def load_schema(self, store, version, filename, module_path): """Load the schema from a file. @@ -206,17 +222,11 @@ class StormBaseDatabase: """ if filename is not None: contents = resource_string('mailman.database.schema', filename) - # Discard all blank and comment lines. - lines = (line for line in contents.splitlines() - if line.strip() != '' and line.strip()[:2] != '--') - sql = NL.join(lines) - for statement in sql.split(';'): - if statement.strip() != '': - store.execute(statement + ';') + self.load_sql(store, contents) # Add a marker that indicates the migration version being applied. store.add(Version(component='schema', version=version)) - # Add a marker so that the module name can be found later. This is - # used by the test suite to reset the database between tests. + # Add a marker so that the module name can be found later. This + # is used by the test suite to reset the database between tests. store.add(Version(component=version, version=module_path)) def _reset(self): @@ -225,3 +235,7 @@ class StormBaseDatabase: self.store.rollback() ModelMeta._reset(self.store) self.store.commit() + + @staticmethod + def _make_temporary(): + raise NotImplementedError -- cgit v1.2.3-70-g09d2