1
# Copyright (c) 2011 Canonical Ltd
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public
14
# License along with this program. If not, see
15
# <http://www.gnu.org/licenses/>.
17
"""Test helpers for working with cassandra."""
21
from fixtures import Fixture, TempDir
22
from pycassa.system_manager import SystemManager
24
from grackle.server.cassandra import workaround_1779
25
from grackle.server.model import create_schema
28
class TemporaryKeyspace(Fixture):
29
"""Create a temporary keyspace.
31
The keyspace is named after a tempdir.
35
super(TemporaryKeyspace, self).setUp()
36
tempdir = self.useFixture(TempDir())
37
self.keyspace = os.path.basename(tempdir.path)
38
self.mgr = SystemManager()
39
workaround_1779(self.mgr.create_keyspace, self.keyspace,
41
self.addCleanup(workaround_1779, self.mgr.drop_keyspace,
45
class TemporaryDB(Fixture):
46
"""Create a temporary usable OOPS DB.
48
The keyspace for it is at self.keyspace.
52
super(TemporaryDB, self).setUp()
53
self.keyspace = self.useFixture(TemporaryKeyspace()).keyspace
54
create_schema('localhost', self.keyspace)