summaryrefslogtreecommitdiff
path: root/tests/backends/postgresql/tests.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2018-04-03 22:21:47 +0200
committerGitHub <noreply@github.com>2018-04-03 22:21:47 +0200
commit816b386d41e58c6ae750f2e57b6614310886a61a (patch)
treecf5af687795da7c38fab6164e1f08878d6447b5c /tests/backends/postgresql/tests.py
parentb2678468aee3526ec2d092a2f20b1d12b15ba12f (diff)
Refs #24791 -- Made PostgreSQL's nodb connection use first PostgresSQL db when 'postgres' db isn't available.
Thanks Tim Graham and Claude Paroz for reviews.
Diffstat (limited to 'tests/backends/postgresql/tests.py')
-rw-r--r--tests/backends/postgresql/tests.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py
index c4810c0960..43bd28eae9 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -2,7 +2,7 @@ import unittest
import warnings
from unittest import mock
-from django.db import DatabaseError, connection
+from django.db import DatabaseError, connection, connections
from django.test import TestCase
@@ -26,10 +26,15 @@ class Tests(TestCase):
with warnings.catch_warnings(record=True) as w:
with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.connect',
side_effect=mocked_connect, autospec=True):
- warnings.simplefilter('always', RuntimeWarning)
- nodb_conn = connection._nodb_connection
+ with mock.patch.object(
+ connection,
+ 'settings_dict',
+ {**connection.settings_dict, 'NAME': 'postgres'},
+ ):
+ warnings.simplefilter('always', RuntimeWarning)
+ nodb_conn = connection._nodb_connection
self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
- self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
+ self.assertEqual(nodb_conn.settings_dict['NAME'], connections['other'].settings_dict['NAME'])
# Check a RuntimeWarning has been emitted
self.assertEqual(len(w), 1)
self.assertEqual(w[0].message.__class__, RuntimeWarning)