File tree 3 files changed +18
-1
lines changed
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -35,3 +35,4 @@ that much better:
35
35
* Denny Huang - https://github.com/denny0223
36
36
* Stefan Wojcik - https://github.com/wojcikstefan
37
37
* John Cass - https://github.com/jcass77
38
+ * Aly Sivji - https://github.com/alysivji
Original file line number Diff line number Diff line change @@ -24,7 +24,15 @@ def _sanitize_settings(settings):
24
24
25
25
# Handle uri style connections
26
26
if "://" in resolved_settings .get ('host' , '' ):
27
- uri_dict = uri_parser .parse_uri (resolved_settings ['host' ])
27
+ # this section pulls the database name from the URI
28
+ # PyMongo requires URI to start with mongodb:// to parse
29
+ # this workaround allows mongomock to work
30
+ uri_to_check = resolved_settings ['host' ]
31
+
32
+ if uri_to_check .startswith ('mongomock://' ):
33
+ uri_to_check = uri_to_check .replace ('mongomock://' , 'mongodb://' )
34
+
35
+ uri_dict = uri_parser .parse_uri (uri_to_check )
28
36
resolved_settings ['db' ] = uri_dict ['database' ]
29
37
30
38
# Add a default name param or use the "db" key if exists
Original file line number Diff line number Diff line change @@ -51,6 +51,14 @@ def test_host_as_uri_string(self):
51
51
self .app .config ['MONGODB_HOST' ] = 'mongodb://localhost:27017/flask_mongoengine_test_db'
52
52
self ._do_persist (db )
53
53
54
+ def test_mongomock_host_as_uri_string (self ):
55
+ """Make sure we can connect to the mongomock object if we specify
56
+ the host as a mongomock URI.
57
+ """
58
+ db = MongoEngine ()
59
+ self .app .config ['MONGODB_HOST' ] = 'mongomock://localhost:27017/flask_mongoengine_test_db'
60
+ self ._do_persist (db )
61
+
54
62
def test_host_as_list (self ):
55
63
"""Make sure MONGODB_HOST can be a list hosts."""
56
64
db = MongoEngine ()
You can’t perform that action at this time.
0 commit comments