@@ -32,45 +32,76 @@ def tearDown(self):
3232 mongoengine .connection ._connections = {}
3333 mongoengine .connection ._dbs = {}
3434
35+ @require_mongomock
36+ def test_connect_raise_if_mongomock_uri_provided (self ):
37+ with pytest .raises (
38+ Exception , match = "Use of mongomock:// URI or 'is_mock' were removed"
39+ ):
40+ connect ("test" , host = "mongomock://localhost" )
41+
42+ @require_mongomock
43+ def test_connect_raise_if_is_mock_provided (self ):
44+ with pytest .raises (
45+ Exception , match = "Use of mongomock:// URI or 'is_mock' were removed"
46+ ):
47+ connect ("test" , host = "mongodb://localhost" , is_mock = True )
48+
3549 @require_mongomock
3650 def test_connect_in_mocking (self ):
3751 """Ensure that the connect() method works properly in mocking."""
38- connect ("mongoenginetest" , host = "mongomock://localhost" )
52+ connect (
53+ "mongoenginetest" ,
54+ host = "mongodb://localhost" ,
55+ mongo_client_class = mongomock .MongoClient ,
56+ )
3957 conn = get_connection ()
4058 assert isinstance (conn , mongomock .MongoClient )
4159
42- connect ("mongoenginetest2" , host = "mongomock://localhost" , alias = "testdb2" )
60+ connect (
61+ "mongoenginetest2" ,
62+ host = "mongodb://localhost" ,
63+ mongo_client_class = mongomock .MongoClient ,
64+ alias = "testdb2" ,
65+ )
4366 conn = get_connection ("testdb2" )
4467 assert isinstance (conn , mongomock .MongoClient )
4568
4669 connect (
4770 "mongoenginetest3" ,
4871 host = "mongodb://localhost" ,
49- is_mock = True ,
72+ mongo_client_class = mongomock . MongoClient ,
5073 alias = "testdb3" ,
5174 )
5275 conn = get_connection ("testdb3" )
5376 assert isinstance (conn , mongomock .MongoClient )
5477
55- connect ("mongoenginetest4" , is_mock = True , alias = "testdb4" )
78+ connect (
79+ "mongoenginetest4" ,
80+ mongo_client_class = mongomock .MongoClient ,
81+ alias = "testdb4" ,
82+ )
5683 conn = get_connection ("testdb4" )
5784 assert isinstance (conn , mongomock .MongoClient )
5885
5986 connect (
6087 host = "mongodb://localhost:27017/mongoenginetest5" ,
61- is_mock = True ,
88+ mongo_client_class = mongomock . MongoClient ,
6289 alias = "testdb5" ,
6390 )
6491 conn = get_connection ("testdb5" )
6592 assert isinstance (conn , mongomock .MongoClient )
6693
67- connect (host = "mongomock://localhost:27017/mongoenginetest6" , alias = "testdb6" )
94+ connect (
95+ host = "mongodb://localhost:27017/mongoenginetest6" ,
96+ mongo_client_class = mongomock .MongoClient ,
97+ alias = "testdb6" ,
98+ )
6899 conn = get_connection ("testdb6" )
69100 assert isinstance (conn , mongomock .MongoClient )
70101
71102 connect (
72- host = "mongomock ://localhost:27017/mongoenginetest7" ,
73- is_mock = True ,
103+ host = "mongodb ://localhost:27017/mongoenginetest7" ,
104+ mongo_client_class = mongomock . MongoClient ,
74105 alias = "testdb7" ,
75106 )
76107 conn = get_connection ("testdb7" )
@@ -84,7 +115,10 @@ def test_default_database_with_mocking(self):
84115 class SomeDocument (Document ):
85116 pass
86117
87- conn = connect (host = "mongomock://localhost:27017/mongoenginetest" )
118+ conn = connect (
119+ host = "mongodb://localhost:27017/mongoenginetest" ,
120+ mongo_client_class = mongomock .MongoClient ,
121+ )
88122 some_document = SomeDocument ()
89123 # database won't exist until we save a document
90124 some_document .save ()
@@ -96,7 +130,10 @@ class SomeDocument(Document):
96130 def test_basic_queries_against_mongomock (self ):
97131 disconnect_all ()
98132
99- connect (host = "mongomock://localhost:27017/mongoenginetest" )
133+ connect (
134+ host = "mongodb://localhost:27017/mongoenginetest" ,
135+ mongo_client_class = mongomock .MongoClient ,
136+ )
100137
101138 class Person (Document ):
102139 name = StringField ()
@@ -129,35 +166,38 @@ def test_connect_with_host_list(self):
129166
130167 Uses mongomock to test w/o needing multiple mongod/mongos processes
131168 """
132- connect (host = ["mongomock ://localhost" ])
169+ connect (host = ["mongodb ://localhost" ], mongo_client_class = mongomock . MongoClient )
133170 conn = get_connection ()
134171 assert isinstance (conn , mongomock .MongoClient )
135172
136- connect (host = [ "mongodb://localhost" ], is_mock = True , alias = "testdb2" )
137- conn = get_connection ( "testdb2" )
138- assert isinstance ( conn , mongomock .MongoClient )
139-
140- connect ( host = [ "localhost" ], is_mock = True , alias = "testdb3" )
173+ connect (
174+ host = [ "localhost" ],
175+ mongo_client_class = mongomock .MongoClient ,
176+ alias = "testdb3" ,
177+ )
141178 conn = get_connection ("testdb3" )
142179 assert isinstance (conn , mongomock .MongoClient )
143180
144181 connect (
145- host = ["mongomock ://localhost:27017" , "mongomock ://localhost:27018" ],
182+ host = ["mongodb ://localhost:27017" , "mongodb ://localhost:27018" ],
146183 alias = "testdb4" ,
184+ mongo_client_class = mongomock .MongoClient ,
147185 )
148186 conn = get_connection ("testdb4" )
149187 assert isinstance (conn , mongomock .MongoClient )
150188
151189 connect (
152190 host = ["mongodb://localhost:27017" , "mongodb://localhost:27018" ],
153- is_mock = True ,
191+ mongo_client_class = mongomock . MongoClient ,
154192 alias = "testdb5" ,
155193 )
156194 conn = get_connection ("testdb5" )
157195 assert isinstance (conn , mongomock .MongoClient )
158196
159197 connect (
160- host = ["localhost:27017" , "localhost:27018" ], is_mock = True , alias = "testdb6"
198+ host = ["localhost:27017" , "localhost:27018" ],
199+ mongo_client_class = mongomock .MongoClient ,
200+ alias = "testdb6" ,
161201 )
162202 conn = get_connection ("testdb6" )
163203 assert isinstance (conn , mongomock .MongoClient )
0 commit comments