本文整理汇总了Python中mongoengine.connection.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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()
示例3: init_db
def init_db(app):
connect('swa_route',
host=app.config['MONGO_HOST'],
port=app.config['MONGO_PORT'],
username=app.config['MONGO_USERNAME'],
password=app.config['MONGO_PASSWORD']
)
示例4: __init__
def __init__(self, ext):
"""
Constructor.
:param ext: instance of :class:`EveMongoengine`.
"""
# get authentication info
username = ext.app.config['MONGO_USERNAME']
password = ext.app.config['MONGO_PASSWORD']
auth = (username, password)
if any(auth) and not all(auth):
raise ConfigException('Must set both USERNAME and PASSWORD '
'or neither')
# try to connect to db
if ext.app.config['MONGO_URI']: # use MONGO_URI if available
self.conn = connect(ext.app.config['MONGO_URI'])
else: # Or just use the usual connection settings
self.conn = connect(ext.app.config['MONGO_DBNAME'],
host=ext.app.config['MONGO_HOST'],
port=ext.app.config['MONGO_PORT'])
self.models = ext.models
self.app = ext.app
# create dummy driver instead of PyMongo, which causes errors
# when instantiating after config was initialized
self.driver = type('Driver', (), {})()
self.driver.db = get_db()
# authenticate
if any(auth):
self.driver.db.authenticate(username, password)
示例5: _pre_setup
def _pre_setup(self):
from mongoengine.connection import connect, disconnect
disconnect()
import urllib, os
pwd = urllib.quote_plus(os.environ['MONGODB_PWD'])
uri = "mongodb://" + os.environ['MONGODB_USR'] + ":" + pwd + "@127.0.0.1/" + self.mongodb_name + "?authMechanism=SCRAM-SHA-1"
connect(self.mongodb_name, host=uri)
super(SearchappTest, self)._pre_setup()
示例6: setUp
def setUp(self):
connect()
self.db = _get_db()
class Person(Document):
name = StringField()
age = IntField()
uid = ObjectIdField()
self.Person = Person
示例7: 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
示例8: __init__
def __init__(self):
try:
host = get_config_value("MONGO", "host")
port = int(get_config_value("MONGO", "port"))
name = get_config_value("MONGO", "name")
disconnect()
connect(db=name, host=host, port=port)
self.conn = get_connection()
except:
logger.error('Connection to MongoDB could not be established.')
示例9: migrate
def migrate():
connect(
yeti_config.mongodb.database,
host=yeti_config.mongodb.host,
port=yeti_config.mongodb.port,
username=yeti_config.mongodb.username,
password=yeti_config.mongodb.password,
connect=True)
db = get_db()
for i in list(db.observable.list_indexes()):
if i.to_dict()['name'] == "value_1":
db.observable.drop_index("value_1")
示例10: setup_database
def setup_database(self, *args, **kwargs):
# Disconnect from the default mongo db, and use a test db instead.
self.disconnect_dbs()
connection.connect(MONGO_TEST_DATABASE_NAME,
alias=settings.MONGO_DATABASE_NAME, tz_aware=True)
for collection in ['account', 'user', 'rhic', 'fs.chunks',
'fs.files']:
print 'importing %s collection' % collection
call(['mongoimport', '--db', MONGO_TEST_DATABASE_NAME,
'-c', collection, '--file',
'%s.json' % os.path.join(settings.DUMP_DIR, collection)])
示例11: _fixture_setup
def _fixture_setup(self):
from mongoengine.connection import connect, disconnect
disconnect()
connect(self.mongodb_name)
from mongoengine.django.mongo_auth.models import MongoUser
if MongoUser.objects.filter(username="admin").count() == 0:
MongoUser.objects.create_superuser("admin", "[email protected]", "admin")
if MongoUser.objects.filter(username="library_user").count() == 0:
MongoUser.objects.create_user("library_user", "[email protected]", "secret")
setup_test_environment()
示例12: _pre_setup
def _pre_setup(self):
"""
Function: _pre_setup
--------------------
Automatically called before any test for connecting to MongoDB.
"""
from mongoengine.connection import connect, disconnect
disconnect()
import urllib, os
pwd = urllib.quote_plus(os.environ['MONGODB_PWD'])
uri = "mongodb://" + os.environ['MONGODB_USR'] + ":" + pwd + "@127.0.0.1/" + self.mongodb_name + "?authMechanism=SCRAM-SHA-1"
connect(self.mongodb_name, host=uri)
super(B2noteappTest, self)._pre_setup()
示例13: setUp
def setUp(self):
db_name = settings.MONGO_DATABASE_NAME_RESULTS
self.db = connect(db_name)
ReportData.drop_collection()
rhel_product = TestData.create_products()
rhel_entry = TestData.create_entry(RHEL, memhigh=True)
rhel_entry.save()
示例14: __init__
def __init__(self, ext):
"""
Constructor.
:param ext: instance of :class:`EveMongoengine`.
"""
# get authentication info
username = ext.app.config['MONGO_USERNAME']
password = ext.app.config['MONGO_PASSWORD']
auth = (username, password)
if any(auth) and not all(auth):
raise ConfigException('Must set both USERNAME and PASSWORD '
'or neither')
# try to connect to db
self.conn = connect(ext.app.config['MONGO_DBNAME'],
host=ext.app.config['MONGO_HOST'],
port=ext.app.config['MONGO_PORT'])
self.models = ext.models
self.app = ext.app
# create dummy driver instead of PyMongo, which causes errors
# when instantiating after config was initialized
self.driver = type('Driver', (), {})()
self.driver.db = get_db()
# authenticate
if any(auth):
self.driver.db.authenticate(username, password)
# helper object for managing PATCHes, which are a bit dirty
self.updater = MongoengineUpdater(self)
# map resource -> Mongoengine class
self.cls_map = ResourceClassMap(self)
示例15: __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)