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 1
1
from django .core .exceptions import ImproperlyConfigured
2
2
from django .db import connection
3
+ from django .db .backends .signals import connection_created
3
4
from django .test import SimpleTestCase , TestCase
4
5
5
6
from django_mongodb_backend .base import DatabaseWrapper
@@ -21,3 +22,23 @@ def test_set_autocommit(self):
21
22
self .assertIs (connection .get_autocommit (), False )
22
23
connection .set_autocommit (True )
23
24
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