Fixed #28578 -- Renamed DatabaseCreation number arguments to suffix.
This commit is contained in:
parent
a0b4ecce57
commit
99e65d6488
|
@ -194,7 +194,7 @@ class BaseDatabaseCreation:
|
||||||
|
|
||||||
return test_database_name
|
return test_database_name
|
||||||
|
|
||||||
def clone_test_db(self, number, verbosity=1, autoclobber=False, keepdb=False):
|
def clone_test_db(self, suffix, verbosity=1, autoclobber=False, keepdb=False):
|
||||||
"""
|
"""
|
||||||
Clone a test database.
|
Clone a test database.
|
||||||
"""
|
"""
|
||||||
|
@ -211,9 +211,9 @@ class BaseDatabaseCreation:
|
||||||
|
|
||||||
# We could skip this call if keepdb is True, but we instead
|
# We could skip this call if keepdb is True, but we instead
|
||||||
# give it the keepdb param. See create_test_db for details.
|
# give it the keepdb param. See create_test_db for details.
|
||||||
self._clone_test_db(number, verbosity, keepdb)
|
self._clone_test_db(suffix, verbosity, keepdb)
|
||||||
|
|
||||||
def get_test_db_clone_settings(self, number):
|
def get_test_db_clone_settings(self, suffix):
|
||||||
"""
|
"""
|
||||||
Return a modified connection settings dict for the n-th clone of a DB.
|
Return a modified connection settings dict for the n-th clone of a DB.
|
||||||
"""
|
"""
|
||||||
|
@ -222,10 +222,10 @@ class BaseDatabaseCreation:
|
||||||
# we don't need to call _get_test_db_name.
|
# we don't need to call _get_test_db_name.
|
||||||
orig_settings_dict = self.connection.settings_dict
|
orig_settings_dict = self.connection.settings_dict
|
||||||
new_settings_dict = orig_settings_dict.copy()
|
new_settings_dict = orig_settings_dict.copy()
|
||||||
new_settings_dict['NAME'] = '{}_{}'.format(orig_settings_dict['NAME'], number)
|
new_settings_dict['NAME'] = '{}_{}'.format(orig_settings_dict['NAME'], suffix)
|
||||||
return new_settings_dict
|
return new_settings_dict
|
||||||
|
|
||||||
def _clone_test_db(self, number, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
"""
|
"""
|
||||||
Internal implementation - duplicate the test db tables.
|
Internal implementation - duplicate the test db tables.
|
||||||
"""
|
"""
|
||||||
|
@ -233,16 +233,16 @@ class BaseDatabaseCreation:
|
||||||
"The database backend doesn't support cloning databases. "
|
"The database backend doesn't support cloning databases. "
|
||||||
"Disable the option to run tests in parallel processes.")
|
"Disable the option to run tests in parallel processes.")
|
||||||
|
|
||||||
def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, number=None):
|
def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, suffix=None):
|
||||||
"""
|
"""
|
||||||
Destroy a test database, prompting the user for confirmation if the
|
Destroy a test database, prompting the user for confirmation if the
|
||||||
database already exists.
|
database already exists.
|
||||||
"""
|
"""
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
if number is None:
|
if suffix is None:
|
||||||
test_database_name = self.connection.settings_dict['NAME']
|
test_database_name = self.connection.settings_dict['NAME']
|
||||||
else:
|
else:
|
||||||
test_database_name = self.get_test_db_clone_settings(number)['NAME']
|
test_database_name = self.get_test_db_clone_settings(suffix)['NAME']
|
||||||
|
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
action = 'Destroying'
|
action = 'Destroying'
|
||||||
|
|
|
@ -38,9 +38,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def _clone_test_db(self, number, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
source_database_name = self.connection.settings_dict['NAME']
|
source_database_name = self.connection.settings_dict['NAME']
|
||||||
target_database_name = self.get_test_db_clone_settings(number)['NAME']
|
target_database_name = self.get_test_db_clone_settings(suffix)['NAME']
|
||||||
test_db_params = {
|
test_db_params = {
|
||||||
'dbname': self.connection.ops.quote_name(target_database_name),
|
'dbname': self.connection.ops.quote_name(target_database_name),
|
||||||
'suffix': self.sql_table_creation_suffix(),
|
'suffix': self.sql_table_creation_suffix(),
|
||||||
|
|
|
@ -43,13 +43,13 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||||
# exists".
|
# exists".
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def _clone_test_db(self, number, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
# CREATE DATABASE ... WITH TEMPLATE ... requires closing connections
|
# CREATE DATABASE ... WITH TEMPLATE ... requires closing connections
|
||||||
# to the template database.
|
# to the template database.
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|
||||||
source_database_name = self.connection.settings_dict['NAME']
|
source_database_name = self.connection.settings_dict['NAME']
|
||||||
target_database_name = self.get_test_db_clone_settings(number)['NAME']
|
target_database_name = self.get_test_db_clone_settings(suffix)['NAME']
|
||||||
test_db_params = {
|
test_db_params = {
|
||||||
'dbname': self._quote_name(target_database_name),
|
'dbname': self._quote_name(target_database_name),
|
||||||
'suffix': self._get_database_create_suffix(template=source_database_name),
|
'suffix': self._get_database_create_suffix(template=source_database_name),
|
||||||
|
|
|
@ -56,7 +56,7 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return test_database_name
|
return test_database_name
|
||||||
|
|
||||||
def get_test_db_clone_settings(self, number):
|
def get_test_db_clone_settings(self, suffix):
|
||||||
orig_settings_dict = self.connection.settings_dict
|
orig_settings_dict = self.connection.settings_dict
|
||||||
source_database_name = orig_settings_dict['NAME']
|
source_database_name = orig_settings_dict['NAME']
|
||||||
if self.is_in_memory_db(source_database_name):
|
if self.is_in_memory_db(source_database_name):
|
||||||
|
@ -64,12 +64,12 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||||
else:
|
else:
|
||||||
new_settings_dict = orig_settings_dict.copy()
|
new_settings_dict = orig_settings_dict.copy()
|
||||||
root, ext = os.path.splitext(orig_settings_dict['NAME'])
|
root, ext = os.path.splitext(orig_settings_dict['NAME'])
|
||||||
new_settings_dict['NAME'] = '{}_{}.{}'.format(root, number, ext)
|
new_settings_dict['NAME'] = '{}_{}.{}'.format(root, suffix, ext)
|
||||||
return new_settings_dict
|
return new_settings_dict
|
||||||
|
|
||||||
def _clone_test_db(self, number, verbosity, keepdb=False):
|
def _clone_test_db(self, suffix, verbosity, keepdb=False):
|
||||||
source_database_name = self.connection.settings_dict['NAME']
|
source_database_name = self.connection.settings_dict['NAME']
|
||||||
target_database_name = self.get_test_db_clone_settings(number)['NAME']
|
target_database_name = self.get_test_db_clone_settings(suffix)['NAME']
|
||||||
# Forking automatically makes a copy of an in-memory database.
|
# Forking automatically makes a copy of an in-memory database.
|
||||||
if not self.is_in_memory_db(source_database_name):
|
if not self.is_in_memory_db(source_database_name):
|
||||||
# Erase the old test database
|
# Erase the old test database
|
||||||
|
|
|
@ -290,7 +290,7 @@ def _init_worker(counter):
|
||||||
|
|
||||||
for alias in connections:
|
for alias in connections:
|
||||||
connection = connections[alias]
|
connection = connections[alias]
|
||||||
settings_dict = connection.creation.get_test_db_clone_settings(_worker_id)
|
settings_dict = connection.creation.get_test_db_clone_settings(str(_worker_id))
|
||||||
# connection.settings_dict must be updated in place for changes to be
|
# connection.settings_dict must be updated in place for changes to be
|
||||||
# reflected in django.db.connections. If the following line assigned
|
# reflected in django.db.connections. If the following line assigned
|
||||||
# connection.settings_dict = settings_dict, new threads would connect
|
# connection.settings_dict = settings_dict, new threads would connect
|
||||||
|
|
|
@ -178,7 +178,7 @@ def setup_databases(verbosity, interactive, keepdb=False, debug_sql=False, paral
|
||||||
if parallel > 1:
|
if parallel > 1:
|
||||||
for index in range(parallel):
|
for index in range(parallel):
|
||||||
connection.creation.clone_test_db(
|
connection.creation.clone_test_db(
|
||||||
number=index + 1,
|
suffix=str(index + 1),
|
||||||
verbosity=verbosity,
|
verbosity=verbosity,
|
||||||
keepdb=keepdb,
|
keepdb=keepdb,
|
||||||
)
|
)
|
||||||
|
@ -292,7 +292,7 @@ def teardown_databases(old_config, verbosity, parallel=0, keepdb=False):
|
||||||
if parallel > 1:
|
if parallel > 1:
|
||||||
for index in range(parallel):
|
for index in range(parallel):
|
||||||
connection.creation.destroy_test_db(
|
connection.creation.destroy_test_db(
|
||||||
number=index + 1,
|
suffix=str(index + 1),
|
||||||
verbosity=verbosity,
|
verbosity=verbosity,
|
||||||
keepdb=keepdb,
|
keepdb=keepdb,
|
||||||
)
|
)
|
||||||
|
|
|
@ -404,6 +404,12 @@ backends.
|
||||||
:class:`~django.db.models.functions.Cast` function for a ``CharField`` if the
|
:class:`~django.db.models.functions.Cast` function for a ``CharField`` if the
|
||||||
``max_length`` argument isn't provided.
|
``max_length`` argument isn't provided.
|
||||||
|
|
||||||
|
* The first argument of ``DatabaseCreation._clone_test_db()`` and
|
||||||
|
``get_test_db_clone_settings()`` is now ``suffix`` rather
|
||||||
|
than ``number`` (in case you want to rename the signatures in your backend
|
||||||
|
for consistency). ``django.test`` also now passes those values as strings
|
||||||
|
rather than as integers.
|
||||||
|
|
||||||
Dropped support for Oracle 11.2
|
Dropped support for Oracle 11.2
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue