diff --git a/mongoengine/connection.py b/mongoengine/connection.py index cb1a731f..5f62d6cf 100644 --- a/mongoengine/connection.py +++ b/mongoengine/connection.py @@ -81,7 +81,7 @@ def disconnect(alias=DEFAULT_CONNECTION_NAME): global _dbs if alias in _connections: - get_connection(alias=alias).disconnect() + get_connection(alias=alias).close() del _connections[alias] if alias in _dbs: del _dbs[alias] diff --git a/tests/test_connection.py b/tests/test_connection.py index e9477b79..1b7b7a22 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -51,6 +51,14 @@ class ConnectionTest(unittest.TestCase): conn = get_connection('testdb') self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient)) + def test_disconnect(self): + """Ensure that the disconnect() method works properly + """ + conn1 = connect('mongoenginetest') + mongoengine.connection.disconnect() + conn2 = connect('mongoenginetest') + self.assertTrue(conn1 is not conn2) + def test_sharing_connections(self): """Ensure that connections are shared when the connection settings are exactly the same """