diff options
| author | Barry Warsaw | 2012-07-25 17:48:47 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2012-07-25 17:48:47 -0400 |
| commit | c15688eb88db81340a7602093134e10e8927b2fc (patch) | |
| tree | 11fc83bf64a436fd39492441e3383a109b02d867 /src/mailman/testing | |
| parent | 3ecb13338d36f7f4bccb609bdb2d54ff11359f8f (diff) | |
| download | mailman-c15688eb88db81340a7602093134e10e8927b2fc.tar.gz mailman-c15688eb88db81340a7602093134e10e8927b2fc.tar.zst mailman-c15688eb88db81340a7602093134e10e8927b2fc.zip | |
Refactor to better handling the difference between a testing database and a
production database.
- Add an IDatabaseFactory interface with two named utility implementations.
The initialization subsystem will either ask for the 'testing' or
'production' factory utility depending on whether we're in the test suite or
not. The testing factory returns an IDatabase that can be _reset().
- initialize_2() now takes an optional `testing` argument, defaulting to
False. The test ConfigLayer will pass in True.
- Remove _reset() from the base database class.
- The ModelMeta now adds a PRESERVE attribute to database classes. This
defaults to False, meaning by default the test framework will reset the
table. The Version table is preserved because it records the schema
migrations.
- Because of the above, we no longer need to support pre_reset() and
post_reset() on migrations.
Also, bin/mailman should allow the standard configuration file search
algorithm to be used except when -C/--config is given.
Diffstat (limited to 'src/mailman/testing')
| -rw-r--r-- | src/mailman/testing/database.py | 47 | ||||
| -rw-r--r-- | src/mailman/testing/layers.py | 2 | ||||
| -rw-r--r-- | src/mailman/testing/testing.cfg | 6 |
3 files changed, 4 insertions, 51 deletions
diff --git a/src/mailman/testing/database.py b/src/mailman/testing/database.py deleted file mode 100644 index b442031fa..000000000 --- a/src/mailman/testing/database.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2012 by the Free Software Foundation, Inc. -# -# This file is part of GNU Mailman. -# -# GNU Mailman is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, either version 3 of the License, or (at your option) -# any later version. -# -# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. - -"""Database test helpers.""" - -from __future__ import absolute_import, print_function, unicode_literals - -__metaclass__ = type -__all__ = [ - 'ResetHelper', - ] - - -from mailman.model.version import Version - - - -class ResetHelper: - """Help with database resets; used by schema migrations.""" - - def __init__(self, version, store): - self.version = version - # Save the entry in the Version table for the test suite reset. This - # will be restored below. - result = store.find(Version, component=version).one() - self.saved = result.version - - def restore(self, store): - # We need to preserve the Version table entry for this migration, - # since its existence defines the fact that the tables have been - # loaded. - store.add(Version(component='schema', version=self.version)) - store.add(Version(component=self.version, version=self.saved)) diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index bbef6d5f4..3a3e1f684 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -127,7 +127,7 @@ class ConfigLayer(MockAndMonkeyLayer): config.create_paths = True config.push('test config', test_config) # Initialize everything else. - initialize.initialize_2() + initialize.initialize_2(testing=True) initialize.initialize_3() # When stderr debugging is enabled, subprocess root loggers should # also be more verbose. diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index 0be01298b..141d74a8f 100644 --- a/src/mailman/testing/testing.cfg +++ b/src/mailman/testing/testing.cfg @@ -18,9 +18,9 @@ # A testing configuration. # For testing against PostgreSQL. -[database] -class: mailman.database.postgresql.PostgreSQLDatabase -url: postgres://barry:barry@localhost/mailman +# [database] +# class: mailman.database.postgresql.PostgreSQLDatabase +# url: postgres://barry:barry@localhost/mailman [mailman] site_owner: noreply@example.com |
