本文整理汇总了Python中mongoengine.connection.disconnect函数的典型用法代码示例。如果您正苦于以下问题:Python disconnect函数的具体用法?Python disconnect怎么用?Python disconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了disconnect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
if os.environ.get('KARDBOARD_SETTINGS'):
os.environ['KARDBOARD_SETTINGS'] = ''
from kardboard import default_settings
default_settings.TEMPLATE_DEBUG = True
from kardboard.views import app
from flask.ext.mongoengine import MongoEngine
from kardboard.util import now
delattr(app, 'db')
from mongoengine.connection import connect, disconnect
disconnect()
app.config.from_object('kardboard.default_settings')
app.config['MONGODB_DB'] = 'kardboard_unittest'
app.config['TESTING'] = True
app.config['CELERY_ALWAYS_EAGER'] = True
connect(app.config['MONGODB_DB'])
app.db = MongoEngine(app)
self.config = app.config
self.app = app.test_client()
self.flask_app = app
self.used_keys = []
self._setup_logging()
self.now = now
super(KardboardTestCase, self).setUp()
示例2: __init__
def __init__(self, method_name='runtest'):
disconnect()
db_name = 'test_%s' % settings.MONGOENGINE['db']
self.database = connect(db_name)[db_name]
super(MongoTestCase, self).__init__(method_name)
示例3: test_connect_disconnect_works_on_same_document
def test_connect_disconnect_works_on_same_document(self):
"""Ensure that the connect/disconnect works properly with a single Document"""
db1 = 'db1'
db2 = 'db2'
# Ensure freshness of the 2 databases through pymongo
client = MongoClient('localhost', 27017)
client.drop_database(db1)
client.drop_database(db2)
# Save in db1
connect(db1)
class User(Document):
name = StringField(required=True)
user1 = User(name='John is in db1').save()
disconnect()
# Make sure save doesnt work at this stage
with self.assertRaises(MongoEngineConnectionError):
User(name='Wont work').save()
# Save in db2
connect(db2)
user2 = User(name='Bob is in db2').save()
disconnect()
db1_users = list(client[db1].user.find())
self.assertEqual(db1_users, [{'_id': user1.id, 'name': 'John is in db1'}])
db2_users = list(client[db2].user.find())
self.assertEqual(db2_users, [{'_id': user2.id, 'name': 'Bob is in db2'}])
示例4: setup_databases
def setup_databases(self, **kwargs):
from mongoengine.connection import connect, disconnect
for db_name, db_alias in settings.MONGO_DATABASES.items():
disconnect(db_alias)
connect(db_name, port=settings.MONGO_PORT)
print 'Creating mongo test database ' + db_name
return super(MongoTestRunner, self).setup_databases(**kwargs)
示例5: _post_teardown
def _post_teardown(self):
from mongoengine.connection import get_connection, disconnect
for db_name, db_alias in settings.MONGO_DATABASES.items():
connection = get_connection(db_alias)
connection.drop_database(db_name)
disconnect(db_alias)
super(MongoTestCase, self)._post_teardown()
示例6: setUp
def setUp(self):
disconnect()
# try docker mongo
host = settings._MONGODB_DATABASE_STR \
% (settings._MONGODB_HOST, self.mongodb_name)
connect(self.mongodb_name, host=host)
self.__test_id=0
示例7: teardown_databases
def teardown_databases(self, old_config, **kwargs):
from mongoengine.connection import get_connection, disconnect
connection = get_connection()
connection.drop_database(self.mongodb_name)
print 'Dropping mongo test database: ' + self.mongodb_name
disconnect()
super(MongoTestRunner, self).teardown_databases(old_config, **kwargs)
示例8: teardown_databases
def teardown_databases(self, *args, **kwargs):
for alias, params in self._iter_test_databases():
connection = get_connection(alias)
print("Dropping test database for alias '%s': %s" % (alias, params['name']))
connection.drop_database(params['name'])
disconnect(alias)
return super(TestRunner, self).teardown_databases(*args, **kwargs)
示例9: _pre_setup
def _pre_setup(self):
from mongoengine.connection import connect, disconnect, get_connection
for db_name, db_alias in settings.MONGO_DATABASES.items():
connection = get_connection(db_alias)
connection.drop_database(db_name)
disconnect(db_alias)
connect(db_name, port=settings.MONGO_PORT)
super(MongoTestCase, self)._pre_setup()
示例10: teardown_databases
def teardown_databases(self, old_config, **kwargs):
from mongoengine.connection import get_connection, disconnect
for db_name, db_alias in settings.MONGO_DATABASES.items():
connection = get_connection(db_alias)
connection.drop_database(db_name)
print 'Dropping mongo test database: ' + db_name
disconnect(db_alias)
super(MongoTestRunner, self).teardown_databases(old_config, **kwargs)
示例11: connect_db
def connect_db(db_alias):
disconnect('default')
# Hack to avoid mongoengine caching connection
User._collection = None
Handin._collection = None
return connect(test_db_name(db_alias))
示例12: setup_databases
def setup_databases(self, **kwangs):
global _running_test
_running_test = True
disconnect()
connect(MONGO_DB)
print 'Creating test-database: ' + MONGO_DB
print 'restoring default data'
call(["mongorestore", "--db", MONGO_DB, DUMP_DIR])
return MONGO_DB
示例13: _pre_setup
def _pre_setup(self):
super(MongoTestCase, self)._pre_setup()
disconnect()
db_name = 'test_%s' % settings.MONGOENGINE['db']
self._database = connect( # pylint: disable=attribute-defined-outside-init
db_name, tz_aware=settings.USE_TZ
)[db_name]
示例14: _post_teardown
def _post_teardown(self):
from mongoengine.connection import get_db, disconnect
database = get_db()
for collection in database.collection_names():
if collection == 'system.indexes' or collection == 'english_words':
continue
database.drop_collection(collection)
disconnect()
super(MongoTestCase, self)._post_teardown()
示例15: drop_database_and_reconnect
def drop_database_and_reconnect(self, reconnect=True):
disconnect()
self.db.drop_database(self.db_name)
# Mongoengine sometimes doesn't recreate unique indexes
# in between test runs, adding the below 'reset' to fix this
# https://github.com/hmarr/mongoengine/issues/422
QuerySet._reset_already_indexed()
if reconnect:
self.db = connect(self.db_name)