Pārlūkot izejas kodu

Added backward compatibility test for ConnectionHandler.databases property.

The ConnectionHandler.databases property is no longer used within
Django, but it is maintained for backward compatibility with 3rd party
packages that have used this private API in the past.
Nick Pope 2 gadi atpakaļ
vecāks
revīzija
d3677043fc
2 mainītis faili ar 11 papildinājumiem un 0 dzēšanām
  1. 3 0
      django/db/utils.py
  2. 8 0
      tests/db_utils/tests.py

+ 3 - 0
django/db/utils.py

@@ -183,6 +183,9 @@ class ConnectionHandler(BaseConnectionHandler):
 
     @property
     def databases(self):
+        # Maintained for backward compatibility as some 3rd party packages have
+        # made use of this private API in the past. It is no longer used within
+        # Django itself.
         return self.settings
 
     def create_connection(self, alias):

+ 8 - 0
tests/db_utils/tests.py

@@ -40,6 +40,14 @@ class ConnectionHandlerTests(SimpleTestCase):
         with self.assertRaisesMessage(ImproperlyConfigured, msg):
             conns["other"].ensure_connection()
 
+    def test_databases_property(self):
+        # The "databases" property is maintained for backwards compatibility
+        # with 3rd party packages. It should be an alias of the "settings"
+        # property.
+        conn = ConnectionHandler({})
+        self.assertNotEqual(conn.settings, {})
+        self.assertEqual(conn.settings, conn.databases)
+
     def test_nonexistent_alias(self):
         msg = "The connection 'nonexistent' doesn't exist."
         conns = ConnectionHandler(