11from unittest .mock import MagicMock , patch
22
3+ import pymongo
34from django .test import SimpleTestCase
45
56import django_mongodb
@@ -19,6 +20,13 @@ def setUp(self):
1920 self .mock_resolver = self .patcher .start ()
2021 self .addCleanup (self .patcher .stop )
2122
23+ @patch ("dns.resolver.resolve" )
24+ def test_uri (self , mock_resolver ):
25+ settings_dict = django_mongodb .parse ("mongodb://cluster0.example.mongodb.net/myDatabase" )
26+ self .assertEqual (settings_dict ["ENGINE" ], "django_mongodb" )
27+ self .assertEqual (settings_dict ["NAME" ], "myDatabase" )
28+ self .assertEqual (settings_dict ["HOST" ], "cluster0.example.mongodb.net" )
29+
2230 @patch ("dns.resolver.resolve" )
2331 def test_srv_uri_with_options (self , mock_resolver ):
2432 settings_dict = django_mongodb .parse (URI )
@@ -56,3 +64,8 @@ def test_ssl_require_kwarg(self, mock_resolver):
5664 def test_test_kwarg (self , mock_resolver ):
5765 settings_dict = django_mongodb .parse (URI , test = {"NAME" : "test_db" })
5866 self .assertEqual (settings_dict ["TEST" ]["NAME" ], "test_db" )
67+
68+ @patch ("dns.resolver.resolve" )
69+ def test_uri_no_prefix (self , mock_resolver ):
70+ with self .assertRaises (pymongo .errors .InvalidURI ):
71+ django_mongodb .parse ("cluster0.example.mongodb.net/myDatabase" )
0 commit comments