summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--MANIFEST.in2
-rw-r--r--keystone/common/sql/util.py42
-rw-r--r--keystone/test.py28
-rw-r--r--tests/backend_sql_disk.conf2
-rw-r--r--tests/test_import_legacy.py7
-rw-r--r--tests/test_no_admin_token_auth.py6
-rw-r--r--tests/test_v3.py5
-rw-r--r--tests/tmp/.gitkeep0
9 files changed, 39 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index bb2b228a..5cce17d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,6 @@ cover/*
covhtml
pep8.txt
nosetests.xml
-*.db
doc/build
.DS_Store
doc/source/modules.rst
@@ -24,7 +23,6 @@ build/
dist/
etc/keystone.conf
etc/logging.conf
-tests/test.db.pristine
-tests/no_admin_token_auth-paste.ini
+tests/tmp/
.project
.pydevproject
diff --git a/MANIFEST.in b/MANIFEST.in
index 93b762f7..2373ea28 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -20,4 +20,4 @@ graft tests
graft tools
graft examples
recursive-include keystone *.json *.xml *.cfg *.pem README *.po *.pot *.sql
-global-exclude *.pyc *.sdx *.log *.db *.swp
+global-exclude *.pyc *.sdx *.log *.db *.swp tests/tmp/*
diff --git a/keystone/common/sql/util.py b/keystone/common/sql/util.py
deleted file mode 100644
index c31e50c0..00000000
--- a/keystone/common/sql/util.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-import os
-import shutil
-
-from keystone.common.sql import core
-from keystone.common.sql import migration
-from keystone import config
-
-
-CONF = config.CONF
-
-
-def setup_test_database():
- try:
- if os.path.exists('test.db'):
- os.unlink('test.db')
- if not os.path.exists('test.db.pristine'):
- migration.db_sync()
- shutil.copyfile('test.db', 'test.db.pristine')
- else:
- shutil.copyfile('test.db.pristine', 'test.db')
- except Exception:
- pass
-
-
-def teardown_test_database():
- core.set_global_engine(None)
diff --git a/keystone/test.py b/keystone/test.py
index 61b424a4..5977537e 100644
--- a/keystone/test.py
+++ b/keystone/test.py
@@ -17,6 +17,7 @@
import datetime
import errno
import os
+import shutil
import socket
import StringIO
import sys
@@ -39,6 +40,7 @@ from keystone import assignment
from keystone import catalog
from keystone.common import kvs
from keystone.common import logging
+from keystone.common import sql
from keystone.common import utils
from keystone.common import wsgi
from keystone import config
@@ -56,6 +58,8 @@ ROOTDIR = os.path.dirname(os.path.abspath(os.curdir))
VENDOR = os.path.join(ROOTDIR, 'vendor')
TESTSDIR = os.path.join(ROOTDIR, 'tests')
ETCDIR = os.path.join(ROOTDIR, 'etc')
+TMPDIR = os.path.join(TESTSDIR, 'tmp')
+
CONF = config.CONF
cd = os.chdir
@@ -76,6 +80,10 @@ def testsdir(*p):
return os.path.join(TESTSDIR, *p)
+def tmpdir(*p):
+ return os.path.join(TMPDIR, *p)
+
+
def checkout_vendor(repo, rev):
# TODO(termie): this function is a good target for some optimizations :PERF
name = repo.split('/')[-1]
@@ -108,6 +116,26 @@ def checkout_vendor(repo, rev):
return revdir
+def setup_test_database():
+ db = tmpdir('test.db')
+ pristine = tmpdir('test.db.pristine')
+
+ try:
+ if os.path.exists(db):
+ os.unlink(db)
+ if not os.path.exists(pristine):
+ sql.migration.db_sync()
+ shutil.copyfile(db, pristine)
+ else:
+ shutil.copyfile(pristine, db)
+ except Exception:
+ pass
+
+
+def teardown_test_database():
+ sql.core.set_global_engine(None)
+
+
class TestClient(object):
def __init__(self, app=None, token=None):
self.app = app
diff --git a/tests/backend_sql_disk.conf b/tests/backend_sql_disk.conf
index a4be9117..0f8dfea7 100644
--- a/tests/backend_sql_disk.conf
+++ b/tests/backend_sql_disk.conf
@@ -1,2 +1,2 @@
[sql]
-connection = sqlite:///test.db
+connection = sqlite:///tmp/test.db
diff --git a/tests/test_import_legacy.py b/tests/test_import_legacy.py
index 2642a2cf..9e164099 100644
--- a/tests/test_import_legacy.py
+++ b/tests/test_import_legacy.py
@@ -25,7 +25,6 @@ from keystone import test
from keystone.catalog.backends import templated as catalog_templated
from keystone.common.sql import legacy
-from keystone.common.sql import util as sql_util
from keystone import config
from keystone import identity
from keystone.identity.backends import sql as identity_sql
@@ -41,17 +40,17 @@ class ImportLegacy(test.TestCase):
test.testsdir('test_overrides.conf'),
test.testsdir('backend_sql.conf'),
test.testsdir('backend_sql_disk.conf')])
- sql_util.setup_test_database()
+ test.setup_test_database()
self.identity_man = identity.Manager()
self.identity_api = identity_sql.Identity()
def tearDown(self):
- sql_util.teardown_test_database()
+ test.teardown_test_database()
super(ImportLegacy, self).tearDown()
def setup_old_database(self, sql_dump):
sql_path = test.testsdir(sql_dump)
- db_path = test.testsdir('%s.db' % sql_dump)
+ db_path = test.tmpdir('%s.db' % sql_dump)
try:
os.unlink(db_path)
except OSError:
diff --git a/tests/test_no_admin_token_auth.py b/tests/test_no_admin_token_auth.py
index 93601140..ffdaa7a8 100644
--- a/tests/test_no_admin_token_auth.py
+++ b/tests/test_no_admin_token_auth.py
@@ -14,7 +14,7 @@ def _generate_paste_config():
new_contents = contents.replace(' admin_token_auth ', ' ')
- with open('no_admin_token_auth-paste.ini', 'w') as f:
+ with open(test.tmpdir('no_admin_token_auth-paste.ini'), 'w') as f:
f.write(new_contents)
@@ -26,12 +26,12 @@ class TestNoAdminTokenAuth(test.TestCase):
_generate_paste_config()
self.admin_app = webtest.TestApp(
- self.loadapp('no_admin_token_auth', name='admin'),
+ self.loadapp(test.tmpdir('no_admin_token_auth'), name='admin'),
extra_environ=dict(REMOTE_ADDR='127.0.0.1'))
def tearDown(self):
self.admin_app = None
- os.remove('no_admin_token_auth-paste.ini')
+ os.remove(test.tmpdir('no_admin_token_auth-paste.ini'))
def test_request_no_admin_token_auth(self):
# This test verifies that if the admin_token_auth middleware isn't
diff --git a/tests/test_v3.py b/tests/test_v3.py
index 52d201bc..bf1c4d11 100644
--- a/tests/test_v3.py
+++ b/tests/test_v3.py
@@ -8,7 +8,6 @@ from keystone import test
from keystone import auth
from keystone.common import serializer
-from keystone.common.sql import util as sql_util
from keystone import config
from keystone.openstack.common import timeutils
from keystone.policy.backends import rules
@@ -37,7 +36,7 @@ class RestfulTestCase(test_content_types.RestfulTestCase):
test.testsdir('backend_sql.conf'),
test.testsdir('backend_sql_disk.conf')])
- sql_util.setup_test_database()
+ test.setup_test_database()
self.load_backends()
self.public_app = webtest.TestApp(
@@ -102,7 +101,7 @@ class RestfulTestCase(test_content_types.RestfulTestCase):
self.admin_server.kill()
self.public_server = None
self.admin_server = None
- sql_util.teardown_test_database()
+ test.teardown_test_database()
# need to reset the plug-ins
auth.controllers.AUTH_METHODS = {}
#drop the policy rules
diff --git a/tests/tmp/.gitkeep b/tests/tmp/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/tmp/.gitkeep