summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2017-10-22 17:30:42 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-12-08 08:55:44 +0100
commit98e05ccde440cc9b768952cc10bc8285f4924e1f (patch)
treee15f6086fb47418e5de6d4b61e079ff98fbc09ab /tests
parent0f00560d45ab2931647b0cbe44a27c37c576c6dc (diff)
Fixed #32233 -- Cleaned-up duplicate connection functionality.
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/tests.py19
-rw-r--r--tests/db_utils/tests.py11
-rw-r--r--tests/utils_tests/test_connection.py10
3 files changed, 25 insertions, 15 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 7172b5e9d9..df0483d26e 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -17,7 +17,8 @@ from unittest import mock, skipIf
from django.conf import settings
from django.core import management, signals
from django.core.cache import (
- DEFAULT_CACHE_ALIAS, CacheKeyWarning, InvalidCacheKey, cache, caches,
+ DEFAULT_CACHE_ALIAS, CacheHandler, CacheKeyWarning, InvalidCacheKey, cache,
+ caches,
)
from django.core.cache.backends.base import InvalidCacheBackendError
from django.core.cache.utils import make_template_fragment_key
@@ -2501,19 +2502,19 @@ class CacheHandlerTest(SimpleTestCase):
self.assertIsNot(c[0], c[1])
def test_nonexistent_alias(self):
- msg = "Could not find config for 'nonexistent' in settings.CACHES"
+ msg = "The connection 'nonexistent' doesn't exist."
with self.assertRaisesMessage(InvalidCacheBackendError, msg):
caches['nonexistent']
def test_nonexistent_backend(self):
+ test_caches = CacheHandler({
+ 'invalid_backend': {
+ 'BACKEND': 'django.nonexistent.NonexistentBackend',
+ },
+ })
msg = (
"Could not find backend 'django.nonexistent.NonexistentBackend': "
"No module named 'django.nonexistent'"
)
- with self.settings(CACHES={
- 'invalid_backend': {
- 'BACKEND': 'django.nonexistent.NonexistentBackend',
- },
- }):
- with self.assertRaisesMessage(InvalidCacheBackendError, msg):
- caches['invalid_backend']
+ with self.assertRaisesMessage(InvalidCacheBackendError, msg):
+ test_caches['invalid_backend']
diff --git a/tests/db_utils/tests.py b/tests/db_utils/tests.py
index ca40d4d1e6..7612c6f2fa 100644
--- a/tests/db_utils/tests.py
+++ b/tests/db_utils/tests.py
@@ -3,10 +3,9 @@ import unittest
from django.core.exceptions import ImproperlyConfigured
from django.db import DEFAULT_DB_ALIAS, ProgrammingError, connection
-from django.db.utils import (
- ConnectionDoesNotExist, ConnectionHandler, load_backend,
-)
+from django.db.utils import ConnectionHandler, load_backend
from django.test import SimpleTestCase, TestCase
+from django.utils.connection import ConnectionDoesNotExist
class ConnectionHandlerTests(SimpleTestCase):
@@ -41,7 +40,7 @@ class ConnectionHandlerTests(SimpleTestCase):
conns['other'].ensure_connection()
def test_nonexistent_alias(self):
- msg = "The connection nonexistent doesn't exist"
+ msg = "The connection 'nonexistent' doesn't exist."
conns = ConnectionHandler({
DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
})
@@ -49,7 +48,7 @@ class ConnectionHandlerTests(SimpleTestCase):
conns['nonexistent']
def test_ensure_defaults_nonexistent_alias(self):
- msg = "The connection nonexistent doesn't exist"
+ msg = "The connection 'nonexistent' doesn't exist."
conns = ConnectionHandler({
DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
})
@@ -57,7 +56,7 @@ class ConnectionHandlerTests(SimpleTestCase):
conns.ensure_defaults('nonexistent')
def test_prepare_test_settings_nonexistent_alias(self):
- msg = "The connection nonexistent doesn't exist"
+ msg = "The connection 'nonexistent' doesn't exist."
conns = ConnectionHandler({
DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
})
diff --git a/tests/utils_tests/test_connection.py b/tests/utils_tests/test_connection.py
new file mode 100644
index 0000000000..d763e0824d
--- /dev/null
+++ b/tests/utils_tests/test_connection.py
@@ -0,0 +1,10 @@
+from django.test import SimpleTestCase
+from django.utils.connection import BaseConnectionHandler
+
+
+class BaseConnectionHandlerTests(SimpleTestCase):
+ def test_create_connection(self):
+ handler = BaseConnectionHandler()
+ msg = 'Subclasses must implement create_connection().'
+ with self.assertRaisesMessage(NotImplementedError, msg):
+ handler.create_connection(None)