1
# Copyright (C) 2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Database factory."""
20
from __future__ import absolute_import, print_function, unicode_literals
25
'DatabaseTemporaryFactory',
26
'DatabaseTestingFactory',
32
from zope.component import getAdapter
33
from zope.interface import implementer
34
from zope.interface.verify import verifyObject
36
from mailman.config import config
37
from mailman.interfaces.database import (
38
IDatabase, IDatabaseFactory, ITemporaryDatabase)
39
from mailman.utilities.modules import call_name
43
@implementer(IDatabaseFactory)
44
class DatabaseFactory:
45
"""Create a new database."""
49
"""See `IDatabaseFactory`."""
50
database_class = config.database['class']
51
database = call_name(database_class)
52
verifyObject(IDatabase, database)
54
database.load_migrations()
61
"""See `IDatabase`."""
62
from mailman.database.model import ModelMeta
64
self._pre_reset(self.store)
65
ModelMeta._reset(self.store)
66
self._post_reset(self.store)
70
@implementer(IDatabaseFactory)
71
class DatabaseTestingFactory:
72
"""Create a new database for testing."""
76
"""See `IDatabaseFactory`."""
77
database_class = config.database['class']
78
database = call_name(database_class)
79
verifyObject(IDatabase, database)
81
database.load_migrations()
83
# Make _reset() a bound method of the database instance.
84
database._reset = types.MethodType(_reset, database)
89
@implementer(IDatabaseFactory)
90
class DatabaseTemporaryFactory:
91
"""Create a temporary database for some of the migration tests."""
95
"""See `IDatabaseFactory`."""
96
database_class_name = config.database['class']
97
database = call_name(database_class_name)
98
verifyObject(IDatabase, database)
99
adapted_database = getAdapter(
100
database, ITemporaryDatabase, database.TAG)
101
return adapted_database