mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Removed support for old-style test database settings per deprecation timeline.
This commit is contained in:
@@ -24,9 +24,8 @@ from django.db.models.sql.constants import CURSOR
|
||||
from django.db.utils import ConnectionHandler
|
||||
from django.test import (TestCase, TransactionTestCase, mock, override_settings,
|
||||
skipUnlessDBFeature, skipIfDBFeature)
|
||||
from django.test.utils import ignore_warnings, str_prefix
|
||||
from django.test.utils import str_prefix
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
from django.utils.six.moves import range
|
||||
|
||||
from . import models
|
||||
@@ -1081,125 +1080,6 @@ class BackendUtilTests(TestCase):
|
||||
'1234600000')
|
||||
|
||||
|
||||
@ignore_warnings(category=UserWarning,
|
||||
message="Overriding setting DATABASES can lead to unexpected behavior")
|
||||
class DBTestSettingsRenamedTests(TestCase):
|
||||
|
||||
mismatch_msg = ("Connection 'test-deprecation' has mismatched TEST "
|
||||
"and TEST_* database settings.")
|
||||
|
||||
def setUp(self):
|
||||
super(DBTestSettingsRenamedTests, self).setUp()
|
||||
self.handler = ConnectionHandler()
|
||||
self.db_settings = {'default': {}}
|
||||
|
||||
def test_mismatched_database_test_settings_1(self):
|
||||
# if the TEST setting is used, all TEST_* keys must appear in it.
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {},
|
||||
'TEST_NAME': 'foo',
|
||||
}
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_mismatched_database_test_settings_2(self):
|
||||
# if the TEST setting is used, all TEST_* keys must match.
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {'NAME': 'foo'},
|
||||
'TEST_NAME': 'bar',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_mismatched_database_test_settings_3(self):
|
||||
# Verifies the mapping of an aliased key.
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {'CREATE_DB': 'foo'},
|
||||
'TEST_CREATE': 'bar',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_mismatched_database_test_settings_4(self):
|
||||
# Verifies the mapping of an aliased key when the aliased key is missing.
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {},
|
||||
'TEST_CREATE': 'bar',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_mismatched_settings_old_none(self):
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {'CREATE_DB': None},
|
||||
'TEST_CREATE': '',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_mismatched_settings_new_none(self):
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {},
|
||||
'TEST_CREATE': None,
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
with self.assertRaisesMessage(ImproperlyConfigured, self.mismatch_msg):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_matched_test_settings(self):
|
||||
# should be able to define new settings and the old, if they match
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {'NAME': 'foo'},
|
||||
'TEST_NAME': 'foo',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_new_settings_only(self):
|
||||
# should be able to define new settings without the old
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST': {'NAME': 'foo'},
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango19Warning)
|
||||
def test_old_settings_only(self):
|
||||
# should be able to define old settings without the new
|
||||
self.db_settings.update({
|
||||
'test-deprecation': {
|
||||
'TEST_NAME': 'foo',
|
||||
},
|
||||
})
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
self.handler.prepare_test_settings('test-deprecation')
|
||||
|
||||
def test_empty_settings(self):
|
||||
with override_settings(DATABASES=self.db_settings):
|
||||
self.handler.prepare_test_settings('default')
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite specific test.')
|
||||
@skipUnlessDBFeature('can_share_in_memory_db')
|
||||
class TestSqliteThreadSharing(TransactionTestCase):
|
||||
|
||||
Reference in New Issue
Block a user