• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python connection.connect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mongoengine.connection.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:iamforeverme,项目名称:seekforjobs,代码行数:7,代码来源:tests.py


示例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()
开发者ID:josephjo,项目名称:kardboard,代码行数:30,代码来源:core.py


示例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']
    )
开发者ID:bandycj,项目名称:SwaRoute,代码行数:7,代码来源:database.py


示例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)
开发者ID:kcaylor,项目名称:eve-mongoengine,代码行数:29,代码来源:datalayer.py


示例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()
开发者ID:ant1b,项目名称:b2note,代码行数:9,代码来源:tests.py


示例6: setUp

    def setUp(self):
        connect()
        self.db = _get_db()

        class Person(Document):
            name = StringField()
            age = IntField()
            uid = ObjectIdField()
        self.Person = Person
开发者ID:andrew-cl,项目名称:mongoengine,代码行数:9,代码来源:document.py


示例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
开发者ID:ihiji,项目名称:django_mongo_testrunners,代码行数:9,代码来源:mongocitestrunner.py


示例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.')
开发者ID:RaikesSchoolDS,项目名称:HTResearch,代码行数:10,代码来源:connection.py


示例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")
开发者ID:raymundl,项目名称:yeti,代码行数:12,代码来源:drop_value_index_5.py


示例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)])
开发者ID:splice,项目名称:rhic-serve,代码行数:12,代码来源:tests.py


示例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()
开发者ID:libris,项目名称:bibstat,代码行数:12,代码来源:__init__.py


示例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()
开发者ID:EUDAT-B2NOTE,项目名称:b2note,代码行数:14,代码来源:tests.py


示例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()
开发者ID:segfault923,项目名称:report_server,代码行数:7,代码来源:tests.py


示例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)
开发者ID:satyanani40,项目名称:eve-mongoengine,代码行数:30,代码来源:datalayer.py


示例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)
开发者ID:coinpayee,项目名称:django-short-urls,代码行数:7,代码来源:mongo_test_case.py


示例16: initDb

def initDb():
    dbServer = {"dbName":"telugubeats",
                       "ip":"104.155.234.161",# "db.quizapp.appsandlabs.com",
                       "port": 27017,
                       "username": "abhinav",
                       "password":"xxxxx"
       }
    dbConnection = connect(dbServer["dbName"], host=dbServer["ip"], port=dbServer["port"], username=dbServer["username"],password=dbServer["password"])
开发者ID:abhinavabcd,项目名称:telugubeats_server,代码行数:8,代码来源:__init__.py


示例17: 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()
    # Drop these indexes as they have changed
    db.schedule_entry.drop_indexes()
    db.one_shot_entry.drop_indexes()
    db.inline_analytics.drop_indexes()
    db.attached_file.drop_indexes()
    change_oneshot_entries(db)
    change_feed_name(db)
    correct_feed_objects()
开发者ID:raymundl,项目名称:yeti,代码行数:17,代码来源:change_oneshot_names_6.py


示例18: 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))
开发者ID:anderslime,项目名称:smache,代码行数:8,代码来源:db_helper.py


示例19: _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]
开发者ID:Work4Labs,项目名称:django-short-urls,代码行数:9,代码来源:mongo_test_case.py


示例20: 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)
开发者ID:segfault923,项目名称:report_server,代码行数:9,代码来源:tests.py



注:本文中的mongoengine.connection.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connection.disconnect函数代码示例发布时间:2022-05-27
下一篇:
Python connection._get_db函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap