summaryrefslogtreecommitdiff
path: root/tests/backends/postgresql/tests.py
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-12-23 23:39:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-01-20 17:30:37 +0100
commitdcb3ad3319cad5c270a1856fd5f355e37cf9d474 (patch)
tree919ded9b849cb0a4ae66052c030f5bfb2e980d1a /tests/backends/postgresql/tests.py
parentf054468cac325e8d8fa4d5934b939b93242a3730 (diff)
Fixed #32292 -- Added support for connection by service name to PostgreSQL.
Diffstat (limited to 'tests/backends/postgresql/tests.py')
-rw-r--r--tests/backends/postgresql/tests.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py
index 8d0a801ea2..94ebfbdaf8 100644
--- a/tests/backends/postgresql/tests.py
+++ b/tests/backends/postgresql/tests.py
@@ -68,6 +68,36 @@ class Tests(TestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
DatabaseWrapper(settings).get_connection_params()
+ def test_database_name_empty(self):
+ from django.db.backends.postgresql.base import DatabaseWrapper
+ settings = connection.settings_dict.copy()
+ settings['NAME'] = ''
+ msg = (
+ "settings.DATABASES is improperly configured. Please supply the "
+ "NAME or OPTIONS['service'] value."
+ )
+ with self.assertRaisesMessage(ImproperlyConfigured, msg):
+ DatabaseWrapper(settings).get_connection_params()
+
+ def test_service_name(self):
+ from django.db.backends.postgresql.base import DatabaseWrapper
+ settings = connection.settings_dict.copy()
+ settings['OPTIONS'] = {'service': 'my_service'}
+ settings['NAME'] = ''
+ params = DatabaseWrapper(settings).get_connection_params()
+ self.assertEqual(params['service'], 'my_service')
+ self.assertNotIn('database', params)
+
+ def test_service_name_default_db(self):
+ # None is used to connect to the default 'postgres' db.
+ from django.db.backends.postgresql.base import DatabaseWrapper
+ settings = connection.settings_dict.copy()
+ settings['NAME'] = None
+ settings['OPTIONS'] = {'service': 'django_test'}
+ params = DatabaseWrapper(settings).get_connection_params()
+ self.assertEqual(params['database'], 'postgres')
+ self.assertNotIn('service', params)
+
def test_connect_and_rollback(self):
"""
PostgreSQL shouldn't roll back SET TIME ZONE, even if the first