summaryrefslogtreecommitdiff
path: root/tests/db_utils
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-12-08 07:05:49 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-12-08 08:54:50 +0100
commit30f2d1af03b1f1e981e8e15151079795914f8f2c (patch)
tree2e3c6dda051d8b8562f259352bf82aeaacb34dd9 /tests/db_utils
parent148702e7258eafb27d5488b33a723c87d898e22b (diff)
downloaddjango-30f2d1af03b1f1e981e8e15151079795914f8f2c.tar.gz
Refs #32233 -- Added tests for nonexistent cache and databases aliases.
Diffstat (limited to 'tests/db_utils')
-rw-r--r--tests/db_utils/tests.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/db_utils/tests.py b/tests/db_utils/tests.py
index 3ce8e82cd3..ca40d4d1e6 100644
--- a/tests/db_utils/tests.py
+++ b/tests/db_utils/tests.py
@@ -3,7 +3,9 @@ import unittest
from django.core.exceptions import ImproperlyConfigured
from django.db import DEFAULT_DB_ALIAS, ProgrammingError, connection
-from django.db.utils import ConnectionHandler, load_backend
+from django.db.utils import (
+ ConnectionDoesNotExist, ConnectionHandler, load_backend,
+)
from django.test import SimpleTestCase, TestCase
@@ -38,6 +40,30 @@ class ConnectionHandlerTests(SimpleTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
conns['other'].ensure_connection()
+ def test_nonexistent_alias(self):
+ msg = "The connection nonexistent doesn't exist"
+ conns = ConnectionHandler({
+ DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
+ })
+ with self.assertRaisesMessage(ConnectionDoesNotExist, msg):
+ conns['nonexistent']
+
+ def test_ensure_defaults_nonexistent_alias(self):
+ msg = "The connection nonexistent doesn't exist"
+ conns = ConnectionHandler({
+ DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
+ })
+ with self.assertRaisesMessage(ConnectionDoesNotExist, msg):
+ conns.ensure_defaults('nonexistent')
+
+ def test_prepare_test_settings_nonexistent_alias(self):
+ msg = "The connection nonexistent doesn't exist"
+ conns = ConnectionHandler({
+ DEFAULT_DB_ALIAS: {'ENGINE': 'django.db.backends.dummy'},
+ })
+ with self.assertRaisesMessage(ConnectionDoesNotExist, msg):
+ conns.prepare_test_settings('nonexistent')
+
class DatabaseErrorWrapperTests(TestCase):