Replace use close method in pymongo

This commit is contained in:
Emmanuel Leblond 2015-08-04 18:02:57 +02:00
parent 9c8ceb6b4e
commit 96cfbb201a
2 changed files with 9 additions and 1 deletions

View File

@ -81,7 +81,7 @@ def disconnect(alias=DEFAULT_CONNECTION_NAME):
global _dbs global _dbs
if alias in _connections: if alias in _connections:
get_connection(alias=alias).disconnect() get_connection(alias=alias).close()
del _connections[alias] del _connections[alias]
if alias in _dbs: if alias in _dbs:
del _dbs[alias] del _dbs[alias]

View File

@ -51,6 +51,14 @@ class ConnectionTest(unittest.TestCase):
conn = get_connection('testdb') conn = get_connection('testdb')
self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient)) 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): def test_sharing_connections(self):
"""Ensure that connections are shared when the connection settings are exactly the same """Ensure that connections are shared when the connection settings are exactly the same
""" """