File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def check_django_compatability():
26
26
)
27
27
28
28
29
- def parse (uri , engine = None ):
29
+ def parse (uri , engine = None , conn_max_age = None , conn_health_checks = None ):
30
30
"""
31
31
Parse a MongoDB URI and return a dictionary of Django database
32
32
settings. This function is a wrapper around PyMongo's
@@ -51,7 +51,7 @@ def parse(uri, engine=None):
51
51
elif len (nodelist ) > 1 :
52
52
host = "," .join ([f"{ host } :{ port } " for host , port in nodelist ])
53
53
54
- return {
54
+ settings_dict = {
55
55
"ENGINE" : engine ,
56
56
"NAME" : uri ["database" ],
57
57
"HOST" : host ,
@@ -61,6 +61,14 @@ def parse(uri, engine=None):
61
61
"OPTIONS" : uri .get ("options" ),
62
62
}
63
63
64
+ if conn_max_age is not None :
65
+ settings_dict ["CONN_MAX_AGE" ] = conn_max_age
66
+
67
+ if conn_health_checks is not None :
68
+ settings_dict ["CONN_HEALTH_CHECKS" ] = conn_health_checks
69
+
70
+ return settings_dict
71
+
64
72
65
73
def set_wrapped_methods (cls ):
66
74
"""Initialize the wrapped methods on cls."""
Original file line number Diff line number Diff line change @@ -33,3 +33,13 @@ def test_parse(self, mock_resolver):
33
33
def test_engine_kwarg (self , mock_resolver ):
34
34
settings_dict = django_mongodb .parse (URI , engine = "some_other_engine" )
35
35
self .assertEqual (settings_dict ["ENGINE" ], "some_other_engine" )
36
+
37
+ @patch ("dns.resolver.resolve" )
38
+ def test_conn_max_age_kwarg (self , mock_resolver ):
39
+ settings_dict = django_mongodb .parse (URI , conn_max_age = 600 )
40
+ self .assertEqual (settings_dict ["CONN_MAX_AGE" ], 600 )
41
+
42
+ @patch ("dns.resolver.resolve" )
43
+ def test_conn_health_checks_kwarg (self , mock_resolver ):
44
+ settings_dict = django_mongodb .parse (URI , conn_health_checks = True )
45
+ self .assertEqual (settings_dict ["CONN_HEALTH_CHECKS" ], True )
You can’t perform that action at this time.
0 commit comments