Refs #31117 -- Moved get_connection_copy() test hook to a module level.

This commit is contained in:
Mariusz Felisiak 2020-01-20 10:47:02 +01:00
parent a920c0b852
commit f34be5294d
1 changed files with 13 additions and 11 deletions

View File

@ -8,19 +8,21 @@ from django.db.backends.base.creation import (
from django.test import SimpleTestCase from django.test import SimpleTestCase
class TestDbSignatureTests(SimpleTestCase): def get_connection_copy():
def get_connection_copy(self):
# Get a copy of the default connection. (Can't use django.db.connection # Get a copy of the default connection. (Can't use django.db.connection
# because it'll modify the default connection itself.) # because it'll modify the default connection itself.)
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS]) test_connection = copy.copy(connections[DEFAULT_DB_ALIAS])
test_connection.settings_dict = copy.copy(connections[DEFAULT_DB_ALIAS].settings_dict) test_connection.settings_dict = copy.deepcopy(
connections[DEFAULT_DB_ALIAS].settings_dict
)
return test_connection return test_connection
class TestDbSignatureTests(SimpleTestCase):
def test_default_name(self): def test_default_name(self):
# A test db name isn't set. # A test db name isn't set.
prod_name = 'hodor' prod_name = 'hodor'
test_connection = self.get_connection_copy() test_connection = get_connection_copy()
test_connection.settings_dict['NAME'] = prod_name test_connection.settings_dict['NAME'] = prod_name
test_connection.settings_dict['TEST'] = {'NAME': None} test_connection.settings_dict['TEST'] = {'NAME': None}
signature = BaseDatabaseCreation(test_connection).test_db_signature() signature = BaseDatabaseCreation(test_connection).test_db_signature()
@ -29,7 +31,7 @@ class TestDbSignatureTests(SimpleTestCase):
def test_custom_test_name(self): def test_custom_test_name(self):
# A regular test db name is set. # A regular test db name is set.
test_name = 'hodor' test_name = 'hodor'
test_connection = self.get_connection_copy() test_connection = get_connection_copy()
test_connection.settings_dict['TEST'] = {'NAME': test_name} test_connection.settings_dict['TEST'] = {'NAME': test_name}
signature = BaseDatabaseCreation(test_connection).test_db_signature() signature = BaseDatabaseCreation(test_connection).test_db_signature()
self.assertEqual(signature[3], test_name) self.assertEqual(signature[3], test_name)
@ -37,7 +39,7 @@ class TestDbSignatureTests(SimpleTestCase):
def test_custom_test_name_with_test_prefix(self): def test_custom_test_name_with_test_prefix(self):
# A test db name prefixed with TEST_DATABASE_PREFIX is set. # A test db name prefixed with TEST_DATABASE_PREFIX is set.
test_name = TEST_DATABASE_PREFIX + 'hodor' test_name = TEST_DATABASE_PREFIX + 'hodor'
test_connection = self.get_connection_copy() test_connection = get_connection_copy()
test_connection.settings_dict['TEST'] = {'NAME': test_name} test_connection.settings_dict['TEST'] = {'NAME': test_name}
signature = BaseDatabaseCreation(test_connection).test_db_signature() signature = BaseDatabaseCreation(test_connection).test_db_signature()
self.assertEqual(signature[3], test_name) self.assertEqual(signature[3], test_name)