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

Python connection.disconnect函数代码示例

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

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



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


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


示例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'}])
开发者ID:MongoEngine,项目名称:mongoengine,代码行数:32,代码来源:test_connection.py


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


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


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


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


示例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)
开发者ID:Miaodeli,项目名称:drf-mongo-filters,代码行数:7,代码来源:mongoutils.py


示例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()
开发者ID:snormore,项目名称:django-mongotesting,代码行数:8,代码来源:testcases.py


示例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)
开发者ID:kkumler,项目名称:django-mongotesting,代码行数:8,代码来源:testrunners.py


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


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


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


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


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


示例16: setUpClass

 def setUpClass(self):
     from app import config
     self.app = start_app(config.Test)
     
     # connect to the test db    
     from mongoengine.connection import connect, disconnect, get_connection
     disconnect()
     from app.database import Database
     self.db = Database(app=self.app)
开发者ID:evancasey,项目名称:sif-vote,代码行数:9,代码来源:sms_tests.py


示例17: _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


示例18: __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


示例19: save_article_result_with_queue

def save_article_result_with_queue(queue):
    disconnect()
    lazy_connect()
    while 1:
        try:
            article = queue.get(timeout=1)
        except Empty:
            break
        save_article_result(article, queue)
        queue.task_done()
开发者ID:SingWang93,项目名称:web_develop,代码行数:10,代码来源:save_article_content.py


示例20: _post_teardown

 def _post_teardown(self):
     """
         Function: _post_teardown
         --------------------
         Automatically called after any test for dropping the DB and disconnecting from MongoDB.
     """
     from mongoengine.connection import get_connection, disconnect
     connection = get_connection()
     connection.drop_database(self.mongodb_name)
     disconnect()
     super(B2noteappTest, self)._post_teardown()
开发者ID:EUDAT-B2NOTE,项目名称:b2note,代码行数:11,代码来源:tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python connection.get_connection函数代码示例发布时间:2022-05-27
下一篇:
Python connection.connect函数代码示例发布时间: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