2011-07-13 17:35:51 +08:00
|
|
|
import sys
|
2013-05-21 23:34:08 +08:00
|
|
|
|
|
|
|
from django.conf import settings
|
2015-01-13 04:20:40 +08:00
|
|
|
from django.db.backends.base.creation import BaseDatabaseCreation
|
2014-09-22 01:15:48 +08:00
|
|
|
from django.db.utils import DatabaseError
|
2016-10-25 03:22:00 +08:00
|
|
|
from django.utils.crypto import get_random_string
|
2015-06-18 05:10:52 +08:00
|
|
|
from django.utils.functional import cached_property
|
2007-06-23 22:16:00 +08:00
|
|
|
|
|
|
|
TEST_DATABASE_PREFIX = 'test_'
|
|
|
|
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
class DatabaseCreation(BaseDatabaseCreation):
|
2012-09-08 03:48:22 +08:00
|
|
|
|
2015-06-18 05:10:52 +08:00
|
|
|
@cached_property
|
|
|
|
def _maindb_connection(self):
|
|
|
|
"""
|
|
|
|
This is analogous to other backends' `_nodb_connection` property,
|
|
|
|
which allows access to an "administrative" connection which can
|
|
|
|
be used to manage the test databases.
|
|
|
|
For Oracle, the only connection that can be used for that purpose
|
|
|
|
is the main (non-test) connection.
|
|
|
|
"""
|
|
|
|
settings_dict = settings.DATABASES[self.connection.alias]
|
|
|
|
user = settings_dict.get('SAVED_USER') or settings_dict['USER']
|
|
|
|
password = settings_dict.get('SAVED_PASSWORD') or settings_dict['PASSWORD']
|
2017-12-11 20:08:45 +08:00
|
|
|
settings_dict = {**settings_dict, 'USER': user, 'PASSWORD': password}
|
2015-06-18 05:10:52 +08:00
|
|
|
DatabaseWrapper = type(self.connection)
|
|
|
|
return DatabaseWrapper(settings_dict, alias=self.connection.alias)
|
|
|
|
|
2014-05-28 05:13:08 +08:00
|
|
|
def _create_test_db(self, verbosity=1, autoclobber=False, keepdb=False):
|
2014-08-26 13:54:37 +08:00
|
|
|
parameters = self._get_test_db_params()
|
2017-11-28 21:12:28 +08:00
|
|
|
with self._maindb_connection.cursor() as cursor:
|
|
|
|
if self._test_database_create():
|
|
|
|
try:
|
|
|
|
self._execute_test_db_creation(cursor, parameters, verbosity, keepdb)
|
|
|
|
except Exception as e:
|
|
|
|
if 'ORA-01543' not in str(e):
|
|
|
|
# All errors except "tablespace already exists" cancel tests
|
|
|
|
sys.stderr.write("Got an error creating the test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
if not autoclobber:
|
|
|
|
confirm = input(
|
|
|
|
"It appears the test database, %s, already exists. "
|
|
|
|
"Type 'yes' to delete it, or 'no' to cancel: " % parameters['user'])
|
|
|
|
if autoclobber or confirm == 'yes':
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Destroying old test database for alias '%s'..." % self.connection.alias)
|
|
|
|
try:
|
|
|
|
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
|
|
|
except DatabaseError as e:
|
|
|
|
if 'ORA-29857' in str(e):
|
|
|
|
self._handle_objects_preventing_db_destruction(cursor, parameters,
|
|
|
|
verbosity, autoclobber)
|
|
|
|
else:
|
|
|
|
# Ran into a database error that isn't about leftover objects in the tablespace
|
|
|
|
sys.stderr.write("Got an error destroying the old test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
except Exception as e:
|
2014-10-15 07:52:21 +08:00
|
|
|
sys.stderr.write("Got an error destroying the old test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
2017-11-28 21:12:28 +08:00
|
|
|
try:
|
|
|
|
self._execute_test_db_creation(cursor, parameters, verbosity, keepdb)
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write("Got an error recreating the test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
else:
|
|
|
|
print("Tests cancelled.")
|
|
|
|
sys.exit(1)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2017-11-28 21:12:28 +08:00
|
|
|
if self._test_user_create():
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Creating test user...")
|
|
|
|
try:
|
|
|
|
self._create_test_user(cursor, parameters, verbosity, keepdb)
|
|
|
|
except Exception as e:
|
|
|
|
if 'ORA-01920' not in str(e):
|
|
|
|
# All errors except "user already exists" cancel tests
|
|
|
|
sys.stderr.write("Got an error creating the test user: %s\n" % e)
|
2008-08-11 20:11:25 +08:00
|
|
|
sys.exit(2)
|
2017-11-28 21:12:28 +08:00
|
|
|
if not autoclobber:
|
|
|
|
confirm = input(
|
|
|
|
"It appears the test user, %s, already exists. Type "
|
|
|
|
"'yes' to delete it, or 'no' to cancel: " % parameters['user'])
|
|
|
|
if autoclobber or confirm == 'yes':
|
|
|
|
try:
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Destroying old test user...")
|
|
|
|
self._destroy_test_user(cursor, parameters, verbosity)
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Creating test user...")
|
|
|
|
self._create_test_user(cursor, parameters, verbosity, keepdb)
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write("Got an error recreating the test user: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
else:
|
|
|
|
print("Tests cancelled.")
|
|
|
|
sys.exit(1)
|
2015-06-18 05:10:52 +08:00
|
|
|
self._maindb_connection.close() # done with main user -- test user and tablespaces created
|
|
|
|
self._switch_to_test_user(parameters)
|
|
|
|
return self.connection.settings_dict['NAME']
|
2014-08-26 01:17:13 +08:00
|
|
|
|
2015-06-18 05:10:52 +08:00
|
|
|
def _switch_to_test_user(self, parameters):
|
|
|
|
"""
|
2017-01-25 07:04:12 +08:00
|
|
|
Switch to the user that's used for creating the test database.
|
|
|
|
|
|
|
|
Oracle doesn't have the concept of separate databases under the same
|
|
|
|
user, so a separate user is used; see _create_test_db(). The main user
|
|
|
|
is also needed for cleanup when testing is completed, so save its
|
|
|
|
credentials in the SAVED_USER/SAVED_PASSWORD key in the settings dict.
|
2015-06-18 05:10:52 +08:00
|
|
|
"""
|
2012-11-27 04:45:21 +08:00
|
|
|
real_settings = settings.DATABASES[self.connection.alias]
|
2014-09-04 20:15:09 +08:00
|
|
|
real_settings['SAVED_USER'] = self.connection.settings_dict['SAVED_USER'] = \
|
|
|
|
self.connection.settings_dict['USER']
|
|
|
|
real_settings['SAVED_PASSWORD'] = self.connection.settings_dict['SAVED_PASSWORD'] = \
|
|
|
|
self.connection.settings_dict['PASSWORD']
|
2014-01-20 08:45:29 +08:00
|
|
|
real_test_settings = real_settings['TEST']
|
|
|
|
test_settings = self.connection.settings_dict['TEST']
|
2014-09-04 20:15:09 +08:00
|
|
|
real_test_settings['USER'] = real_settings['USER'] = test_settings['USER'] = \
|
2014-08-26 13:54:37 +08:00
|
|
|
self.connection.settings_dict['USER'] = parameters['user']
|
|
|
|
real_settings['PASSWORD'] = self.connection.settings_dict['PASSWORD'] = parameters['password']
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2015-06-04 23:24:31 +08:00
|
|
|
def set_as_test_mirror(self, primary_settings_dict):
|
|
|
|
"""
|
2017-01-25 07:04:12 +08:00
|
|
|
Set this database up to be used in testing as a mirror of a primary
|
|
|
|
database whose settings are given.
|
2015-06-04 23:24:31 +08:00
|
|
|
"""
|
|
|
|
self.connection.settings_dict['USER'] = primary_settings_dict['USER']
|
|
|
|
self.connection.settings_dict['PASSWORD'] = primary_settings_dict['PASSWORD']
|
|
|
|
|
2014-10-15 07:52:21 +08:00
|
|
|
def _handle_objects_preventing_db_destruction(self, cursor, parameters, verbosity, autoclobber):
|
|
|
|
# There are objects in the test tablespace which prevent dropping it
|
|
|
|
# The easy fix is to drop the test user -- but are we allowed to do so?
|
|
|
|
print("There are objects in the old test database which prevent its destruction.")
|
|
|
|
print("If they belong to the test user, deleting the user will allow the test "
|
|
|
|
"database to be recreated.")
|
|
|
|
print("Otherwise, you will need to find and remove each of these objects, "
|
|
|
|
"or use a different tablespace.\n")
|
|
|
|
if self._test_user_create():
|
|
|
|
if not autoclobber:
|
|
|
|
confirm = input("Type 'yes' to delete user %s: " % parameters['user'])
|
|
|
|
if autoclobber or confirm == 'yes':
|
|
|
|
try:
|
|
|
|
if verbosity >= 1:
|
|
|
|
print("Destroying old test user...")
|
|
|
|
self._destroy_test_user(cursor, parameters, verbosity)
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write("Got an error destroying the test user: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
try:
|
|
|
|
if verbosity >= 1:
|
2015-07-30 18:56:54 +08:00
|
|
|
print("Destroying old test database for alias '%s'..." % self.connection.alias)
|
2014-10-15 07:52:21 +08:00
|
|
|
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
|
|
|
except Exception as e:
|
|
|
|
sys.stderr.write("Got an error destroying the test database: %s\n" % e)
|
|
|
|
sys.exit(2)
|
|
|
|
else:
|
|
|
|
print("Tests cancelled -- test database cannot be recreated.")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print("Django is configured to use pre-existing test user '%s',"
|
|
|
|
" and will not attempt to delete it.\n" % parameters['user'])
|
|
|
|
print("Tests cancelled -- test database cannot be recreated.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2008-08-11 20:11:25 +08:00
|
|
|
def _destroy_test_db(self, test_database_name, verbosity=1):
|
|
|
|
"""
|
|
|
|
Destroy a test database, prompting the user for confirmation if the
|
2017-01-25 07:04:12 +08:00
|
|
|
database already exists. Return the name of the test database created.
|
2008-08-11 20:11:25 +08:00
|
|
|
"""
|
2012-02-29 05:23:45 +08:00
|
|
|
self.connection.settings_dict['USER'] = self.connection.settings_dict['SAVED_USER']
|
|
|
|
self.connection.settings_dict['PASSWORD'] = self.connection.settings_dict['SAVED_PASSWORD']
|
2015-06-18 05:10:52 +08:00
|
|
|
self.connection.close()
|
2014-08-26 13:54:37 +08:00
|
|
|
parameters = self._get_test_db_params()
|
2017-11-28 21:12:28 +08:00
|
|
|
with self._maindb_connection.cursor() as cursor:
|
|
|
|
if self._test_user_create():
|
|
|
|
if verbosity >= 1:
|
|
|
|
print('Destroying test user...')
|
|
|
|
self._destroy_test_user(cursor, parameters, verbosity)
|
|
|
|
if self._test_database_create():
|
|
|
|
if verbosity >= 1:
|
|
|
|
print('Destroying test database tables...')
|
|
|
|
self._execute_test_db_destruction(cursor, parameters, verbosity)
|
2015-06-18 05:10:52 +08:00
|
|
|
self._maindb_connection.close()
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2015-09-26 04:35:36 +08:00
|
|
|
def _execute_test_db_creation(self, cursor, parameters, verbosity, keepdb=False):
|
2008-08-11 20:11:25 +08:00
|
|
|
if verbosity >= 2:
|
2014-08-26 13:54:37 +08:00
|
|
|
print("_create_test_db(): dbname = %s" % parameters['user'])
|
2008-08-11 20:11:25 +08:00
|
|
|
statements = [
|
|
|
|
"""CREATE TABLESPACE %(tblspace)s
|
2017-06-03 00:35:56 +08:00
|
|
|
DATAFILE '%(datafile)s' SIZE %(size)s
|
|
|
|
REUSE AUTOEXTEND ON NEXT %(extsize)s MAXSIZE %(maxsize)s
|
2008-08-11 20:11:25 +08:00
|
|
|
""",
|
|
|
|
"""CREATE TEMPORARY TABLESPACE %(tblspace_temp)s
|
2017-06-03 00:35:56 +08:00
|
|
|
TEMPFILE '%(datafile_tmp)s' SIZE %(size_tmp)s
|
|
|
|
REUSE AUTOEXTEND ON NEXT %(extsize_tmp)s MAXSIZE %(maxsize_tmp)s
|
2008-08-11 20:11:25 +08:00
|
|
|
""",
|
|
|
|
]
|
2015-09-26 04:35:36 +08:00
|
|
|
# Ignore "tablespace already exists" error when keepdb is on.
|
|
|
|
acceptable_ora_err = 'ORA-01543' if keepdb else None
|
|
|
|
self._execute_allow_fail_statements(cursor, statements, parameters, verbosity, acceptable_ora_err)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2015-09-26 04:35:36 +08:00
|
|
|
def _create_test_user(self, cursor, parameters, verbosity, keepdb=False):
|
2008-08-11 20:11:25 +08:00
|
|
|
if verbosity >= 2:
|
2012-04-29 00:02:01 +08:00
|
|
|
print("_create_test_user(): username = %s" % parameters['user'])
|
2008-08-11 20:11:25 +08:00
|
|
|
statements = [
|
|
|
|
"""CREATE USER %(user)s
|
2016-11-02 21:44:15 +08:00
|
|
|
IDENTIFIED BY "%(password)s"
|
2008-08-11 20:11:25 +08:00
|
|
|
DEFAULT TABLESPACE %(tblspace)s
|
|
|
|
TEMPORARY TABLESPACE %(tblspace_temp)s
|
2013-07-06 10:38:33 +08:00
|
|
|
QUOTA UNLIMITED ON %(tblspace)s
|
2008-08-11 20:11:25 +08:00
|
|
|
""",
|
2014-09-22 01:15:48 +08:00
|
|
|
"""GRANT CREATE SESSION,
|
|
|
|
CREATE TABLE,
|
|
|
|
CREATE SEQUENCE,
|
|
|
|
CREATE PROCEDURE,
|
|
|
|
CREATE TRIGGER
|
|
|
|
TO %(user)s""",
|
2008-08-11 20:11:25 +08:00
|
|
|
]
|
2015-09-26 04:35:36 +08:00
|
|
|
# Ignore "user already exists" error when keepdb is on
|
|
|
|
acceptable_ora_err = 'ORA-01920' if keepdb else None
|
2016-10-25 03:22:00 +08:00
|
|
|
success = self._execute_allow_fail_statements(cursor, statements, parameters, verbosity, acceptable_ora_err)
|
|
|
|
# If the password was randomly generated, change the user accordingly.
|
|
|
|
if not success and self._test_settings_get('PASSWORD') is None:
|
2016-11-02 21:44:15 +08:00
|
|
|
set_password = 'ALTER USER %(user)s IDENTIFIED BY "%(password)s"'
|
2016-10-25 03:22:00 +08:00
|
|
|
self._execute_statements(cursor, [set_password], parameters, verbosity)
|
2014-09-22 01:15:48 +08:00
|
|
|
# Most test-suites can be run without the create-view privilege. But some need it.
|
|
|
|
extra = "GRANT CREATE VIEW TO %(user)s"
|
2015-09-26 04:35:36 +08:00
|
|
|
success = self._execute_allow_fail_statements(cursor, [extra], parameters, verbosity, 'ORA-01031')
|
|
|
|
if not success and verbosity >= 2:
|
|
|
|
print("Failed to grant CREATE VIEW permission to test user. This may be ok.")
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2008-08-13 02:49:44 +08:00
|
|
|
def _execute_test_db_destruction(self, cursor, parameters, verbosity):
|
2008-08-11 20:11:25 +08:00
|
|
|
if verbosity >= 2:
|
2014-08-26 13:54:37 +08:00
|
|
|
print("_execute_test_db_destruction(): dbname=%s" % parameters['user'])
|
2008-08-11 20:11:25 +08:00
|
|
|
statements = [
|
|
|
|
'DROP TABLESPACE %(tblspace)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS',
|
|
|
|
'DROP TABLESPACE %(tblspace_temp)s INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS',
|
2013-07-08 08:39:54 +08:00
|
|
|
]
|
2008-08-13 02:49:44 +08:00
|
|
|
self._execute_statements(cursor, statements, parameters, verbosity)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2008-08-13 02:49:44 +08:00
|
|
|
def _destroy_test_user(self, cursor, parameters, verbosity):
|
2008-08-11 20:11:25 +08:00
|
|
|
if verbosity >= 2:
|
2012-04-29 00:02:01 +08:00
|
|
|
print("_destroy_test_user(): user=%s" % parameters['user'])
|
|
|
|
print("Be patient. This can take some time...")
|
2008-08-11 20:11:25 +08:00
|
|
|
statements = [
|
|
|
|
'DROP USER %(user)s CASCADE',
|
2007-06-23 22:16:00 +08:00
|
|
|
]
|
2008-08-13 02:49:44 +08:00
|
|
|
self._execute_statements(cursor, statements, parameters, verbosity)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2014-09-22 01:15:48 +08:00
|
|
|
def _execute_statements(self, cursor, statements, parameters, verbosity, allow_quiet_fail=False):
|
2008-08-11 20:11:25 +08:00
|
|
|
for template in statements:
|
|
|
|
stmt = template % parameters
|
|
|
|
if verbosity >= 2:
|
2012-04-29 00:02:01 +08:00
|
|
|
print(stmt)
|
2008-08-11 20:11:25 +08:00
|
|
|
try:
|
|
|
|
cursor.execute(stmt)
|
2012-04-29 00:09:37 +08:00
|
|
|
except Exception as err:
|
2014-09-22 01:15:48 +08:00
|
|
|
if (not allow_quiet_fail) or verbosity >= 2:
|
|
|
|
sys.stderr.write("Failed (%s)\n" % (err))
|
2008-08-11 20:11:25 +08:00
|
|
|
raise
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2015-09-26 04:35:36 +08:00
|
|
|
def _execute_allow_fail_statements(self, cursor, statements, parameters, verbosity, acceptable_ora_err):
|
|
|
|
"""
|
|
|
|
Execute statements which are allowed to fail silently if the Oracle
|
|
|
|
error code given by `acceptable_ora_err` is raised. Return True if the
|
|
|
|
statements execute without an exception, or False otherwise.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
# Statement can fail when acceptable_ora_err is not None
|
|
|
|
allow_quiet_fail = acceptable_ora_err is not None and len(acceptable_ora_err) > 0
|
|
|
|
self._execute_statements(cursor, statements, parameters, verbosity, allow_quiet_fail=allow_quiet_fail)
|
|
|
|
return True
|
|
|
|
except DatabaseError as err:
|
|
|
|
description = str(err)
|
|
|
|
if acceptable_ora_err is None or acceptable_ora_err not in description:
|
|
|
|
raise
|
|
|
|
return False
|
|
|
|
|
2014-08-26 13:54:37 +08:00
|
|
|
def _get_test_db_params(self):
|
|
|
|
return {
|
|
|
|
'dbname': self._test_database_name(),
|
|
|
|
'user': self._test_database_user(),
|
|
|
|
'password': self._test_database_passwd(),
|
|
|
|
'tblspace': self._test_database_tblspace(),
|
|
|
|
'tblspace_temp': self._test_database_tblspace_tmp(),
|
|
|
|
'datafile': self._test_database_tblspace_datafile(),
|
|
|
|
'datafile_tmp': self._test_database_tblspace_tmp_datafile(),
|
2017-06-03 00:35:56 +08:00
|
|
|
'maxsize': self._test_database_tblspace_maxsize(),
|
|
|
|
'maxsize_tmp': self._test_database_tblspace_tmp_maxsize(),
|
|
|
|
'size': self._test_database_tblspace_size(),
|
|
|
|
'size_tmp': self._test_database_tblspace_tmp_size(),
|
|
|
|
'extsize': self._test_database_tblspace_extsize(),
|
|
|
|
'extsize_tmp': self._test_database_tblspace_tmp_extsize(),
|
2014-08-26 13:54:37 +08:00
|
|
|
}
|
|
|
|
|
2014-01-20 08:45:29 +08:00
|
|
|
def _test_settings_get(self, key, default=None, prefixed=None):
|
|
|
|
"""
|
2017-01-25 07:04:12 +08:00
|
|
|
Return a value from the test settings dict, or a given default, or a
|
|
|
|
prefixed entry from the main settings dict.
|
2014-01-20 08:45:29 +08:00
|
|
|
"""
|
|
|
|
settings_dict = self.connection.settings_dict
|
|
|
|
val = settings_dict['TEST'].get(key, default)
|
2016-10-25 03:22:00 +08:00
|
|
|
if val is None and prefixed:
|
2014-01-20 08:45:29 +08:00
|
|
|
val = TEST_DATABASE_PREFIX + settings_dict[prefixed]
|
|
|
|
return val
|
|
|
|
|
2010-12-21 09:36:09 +08:00
|
|
|
def _test_database_name(self):
|
2014-01-20 08:45:29 +08:00
|
|
|
return self._test_settings_get('NAME', prefixed='NAME')
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_database_create(self):
|
2014-01-20 08:45:29 +08:00
|
|
|
return self._test_settings_get('CREATE_DB', default=True)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_user_create(self):
|
2014-01-20 08:45:29 +08:00
|
|
|
return self._test_settings_get('CREATE_USER', default=True)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_database_user(self):
|
2014-01-20 08:45:29 +08:00
|
|
|
return self._test_settings_get('USER', prefixed='USER')
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_database_passwd(self):
|
2016-10-25 03:22:00 +08:00
|
|
|
password = self._test_settings_get('PASSWORD')
|
|
|
|
if password is None and self._test_user_create():
|
|
|
|
# Oracle passwords are limited to 30 chars and can't contain symbols.
|
|
|
|
password = get_random_string(length=30)
|
|
|
|
return password
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_database_tblspace(self):
|
2014-08-26 13:54:37 +08:00
|
|
|
return self._test_settings_get('TBLSPACE', prefixed='USER')
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2009-12-22 23:18:51 +08:00
|
|
|
def _test_database_tblspace_tmp(self):
|
2014-01-20 08:45:29 +08:00
|
|
|
settings_dict = self.connection.settings_dict
|
|
|
|
return settings_dict['TEST'].get('TBLSPACE_TMP',
|
2014-08-26 13:54:37 +08:00
|
|
|
TEST_DATABASE_PREFIX + settings_dict['USER'] + '_temp')
|
|
|
|
|
|
|
|
def _test_database_tblspace_datafile(self):
|
|
|
|
tblspace = '%s.dbf' % self._test_database_tblspace()
|
|
|
|
return self._test_settings_get('DATAFILE', default=tblspace)
|
|
|
|
|
|
|
|
def _test_database_tblspace_tmp_datafile(self):
|
|
|
|
tblspace = '%s.dbf' % self._test_database_tblspace_tmp()
|
|
|
|
return self._test_settings_get('DATAFILE_TMP', default=tblspace)
|
|
|
|
|
2017-06-03 00:35:56 +08:00
|
|
|
def _test_database_tblspace_maxsize(self):
|
2014-08-26 13:54:37 +08:00
|
|
|
return self._test_settings_get('DATAFILE_MAXSIZE', default='500M')
|
|
|
|
|
2017-06-03 00:35:56 +08:00
|
|
|
def _test_database_tblspace_tmp_maxsize(self):
|
2014-08-26 13:54:37 +08:00
|
|
|
return self._test_settings_get('DATAFILE_TMP_MAXSIZE', default='500M')
|
2010-12-21 09:36:09 +08:00
|
|
|
|
2017-06-03 00:35:56 +08:00
|
|
|
def _test_database_tblspace_size(self):
|
|
|
|
return self._test_settings_get('DATAFILE_SIZE', default='50M')
|
|
|
|
|
|
|
|
def _test_database_tblspace_tmp_size(self):
|
|
|
|
return self._test_settings_get('DATAFILE_TMP_SIZE', default='50M')
|
|
|
|
|
|
|
|
def _test_database_tblspace_extsize(self):
|
|
|
|
return self._test_settings_get('DATAFILE_EXTSIZE', default='25M')
|
|
|
|
|
|
|
|
def _test_database_tblspace_tmp_extsize(self):
|
|
|
|
return self._test_settings_get('DATAFILE_TMP_EXTSIZE', default='25M')
|
|
|
|
|
2010-12-21 09:36:09 +08:00
|
|
|
def _get_test_db_name(self):
|
|
|
|
"""
|
2017-01-25 07:04:12 +08:00
|
|
|
Return the 'production' DB name to get the test DB creation machinery
|
|
|
|
to work. This isn't a great deal in this case because DB names as
|
|
|
|
handled by Django don't have real counterparts in Oracle.
|
2010-12-21 09:36:09 +08:00
|
|
|
"""
|
|
|
|
return self.connection.settings_dict['NAME']
|
2011-02-02 22:02:14 +08:00
|
|
|
|
|
|
|
def test_db_signature(self):
|
|
|
|
settings_dict = self.connection.settings_dict
|
|
|
|
return (
|
|
|
|
settings_dict['HOST'],
|
|
|
|
settings_dict['PORT'],
|
|
|
|
settings_dict['ENGINE'],
|
|
|
|
settings_dict['NAME'],
|
2011-02-19 15:41:17 +08:00
|
|
|
self._test_database_user(),
|
2011-02-02 22:02:14 +08:00
|
|
|
)
|