@@ -32,45 +32,76 @@ def tearDown(self):
32
32
mongoengine .connection ._connections = {}
33
33
mongoengine .connection ._dbs = {}
34
34
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
+
35
49
@require_mongomock
36
50
def test_connect_in_mocking (self ):
37
51
"""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
+ )
39
57
conn = get_connection ()
40
58
assert isinstance (conn , mongomock .MongoClient )
41
59
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
+ )
43
66
conn = get_connection ("testdb2" )
44
67
assert isinstance (conn , mongomock .MongoClient )
45
68
46
69
connect (
47
70
"mongoenginetest3" ,
48
71
host = "mongodb://localhost" ,
49
- is_mock = True ,
72
+ mongo_client_class = mongomock . MongoClient ,
50
73
alias = "testdb3" ,
51
74
)
52
75
conn = get_connection ("testdb3" )
53
76
assert isinstance (conn , mongomock .MongoClient )
54
77
55
- connect ("mongoenginetest4" , is_mock = True , alias = "testdb4" )
78
+ connect (
79
+ "mongoenginetest4" ,
80
+ mongo_client_class = mongomock .MongoClient ,
81
+ alias = "testdb4" ,
82
+ )
56
83
conn = get_connection ("testdb4" )
57
84
assert isinstance (conn , mongomock .MongoClient )
58
85
59
86
connect (
60
87
host = "mongodb://localhost:27017/mongoenginetest5" ,
61
- is_mock = True ,
88
+ mongo_client_class = mongomock . MongoClient ,
62
89
alias = "testdb5" ,
63
90
)
64
91
conn = get_connection ("testdb5" )
65
92
assert isinstance (conn , mongomock .MongoClient )
66
93
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
+ )
68
99
conn = get_connection ("testdb6" )
69
100
assert isinstance (conn , mongomock .MongoClient )
70
101
71
102
connect (
72
- host = "mongomock ://localhost:27017/mongoenginetest7" ,
73
- is_mock = True ,
103
+ host = "mongodb ://localhost:27017/mongoenginetest7" ,
104
+ mongo_client_class = mongomock . MongoClient ,
74
105
alias = "testdb7" ,
75
106
)
76
107
conn = get_connection ("testdb7" )
@@ -84,7 +115,10 @@ def test_default_database_with_mocking(self):
84
115
class SomeDocument (Document ):
85
116
pass
86
117
87
- conn = connect (host = "mongomock://localhost:27017/mongoenginetest" )
118
+ conn = connect (
119
+ host = "mongodb://localhost:27017/mongoenginetest" ,
120
+ mongo_client_class = mongomock .MongoClient ,
121
+ )
88
122
some_document = SomeDocument ()
89
123
# database won't exist until we save a document
90
124
some_document .save ()
@@ -96,7 +130,10 @@ class SomeDocument(Document):
96
130
def test_basic_queries_against_mongomock (self ):
97
131
disconnect_all ()
98
132
99
- connect (host = "mongomock://localhost:27017/mongoenginetest" )
133
+ connect (
134
+ host = "mongodb://localhost:27017/mongoenginetest" ,
135
+ mongo_client_class = mongomock .MongoClient ,
136
+ )
100
137
101
138
class Person (Document ):
102
139
name = StringField ()
@@ -129,35 +166,38 @@ def test_connect_with_host_list(self):
129
166
130
167
Uses mongomock to test w/o needing multiple mongod/mongos processes
131
168
"""
132
- connect (host = ["mongomock ://localhost" ])
169
+ connect (host = ["mongodb ://localhost" ], mongo_client_class = mongomock . MongoClient )
133
170
conn = get_connection ()
134
171
assert isinstance (conn , mongomock .MongoClient )
135
172
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
+ )
141
178
conn = get_connection ("testdb3" )
142
179
assert isinstance (conn , mongomock .MongoClient )
143
180
144
181
connect (
145
- host = ["mongomock ://localhost:27017" , "mongomock ://localhost:27018" ],
182
+ host = ["mongodb ://localhost:27017" , "mongodb ://localhost:27018" ],
146
183
alias = "testdb4" ,
184
+ mongo_client_class = mongomock .MongoClient ,
147
185
)
148
186
conn = get_connection ("testdb4" )
149
187
assert isinstance (conn , mongomock .MongoClient )
150
188
151
189
connect (
152
190
host = ["mongodb://localhost:27017" , "mongodb://localhost:27018" ],
153
- is_mock = True ,
191
+ mongo_client_class = mongomock . MongoClient ,
154
192
alias = "testdb5" ,
155
193
)
156
194
conn = get_connection ("testdb5" )
157
195
assert isinstance (conn , mongomock .MongoClient )
158
196
159
197
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" ,
161
201
)
162
202
conn = get_connection ("testdb6" )
163
203
assert isinstance (conn , mongomock .MongoClient )
0 commit comments