File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 11from django .core .exceptions import ImproperlyConfigured
22from django .db import connection
3+ from django .db .backends .signals import connection_created
34from django .test import SimpleTestCase , TestCase
45
56from django_mongodb_backend .base import DatabaseWrapper
@@ -21,3 +22,23 @@ def test_set_autocommit(self):
2122 self .assertIs (connection .get_autocommit (), False )
2223 connection .set_autocommit (True )
2324 self .assertIs (connection .get_autocommit (), True )
25+
26+ def test_connection_created_database_attr (self ):
27+ """
28+ connection.database is available in the connection_created signal.
29+ """
30+ data = {}
31+
32+ def receiver (sender , connection , ** kwargs ): # noqa: ARG001
33+ data ["database" ] = connection .database
34+
35+ connection_created .connect (receiver )
36+ connection .close ()
37+ # Accessing database implicitly connects.
38+ connection .database # noqa: B018
39+ self .assertIs (data ["database" ], connection .database )
40+ connection .close ()
41+ connection_created .disconnect (receiver )
42+ data .clear ()
43+ connection .connect ()
44+ self .assertEqual (data , {})
You can’t perform that action at this time.
0 commit comments