当前位置: 首页>>代码示例>>Python>>正文


Python connection.get_connection函数代码示例

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


在下文中一共展示了get_connection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_connection_kwargs

    def test_connection_kwargs(self):
        """Ensure that connection kwargs get passed to pymongo."""
        connect('mongoenginetest', alias='t1', tz_aware=True)
        conn = get_connection('t1')

        self.assertTrue(get_tz_awareness(conn))

        connect('mongoenginetest2', alias='t2')
        conn = get_connection('t2')
        self.assertFalse(get_tz_awareness(conn))
开发者ID:MongoEngine,项目名称:mongoengine,代码行数:10,代码来源:test_connection.py

示例2: test_sharing_connections

    def test_sharing_connections(self):
        """Ensure that connections are shared when the connection settings are exactly the same
        """
        connect('mongoenginetest', alias='testdb1')

        expected_connection = get_connection('testdb1')

        connect('mongoenginetest', alias='testdb2')
        actual_connection = get_connection('testdb2')
        self.assertEqual(expected_connection, actual_connection)
开发者ID:ThisGuyCodes,项目名称:mongoengine,代码行数:10,代码来源:test_connection.py

示例3: test_connection_kwargs

    def test_connection_kwargs(self):
        """Ensure that connection kwargs get passed to pymongo.
        """
        connect("mongoenginetest", alias="t1", tz_aware=True)
        conn = get_connection("t1")

        self.assertTrue(conn.tz_aware)

        connect("mongoenginetest2", alias="t2")
        conn = get_connection("t2")
        self.assertFalse(conn.tz_aware)
开发者ID:satyanani40,项目名称:mongoengine,代码行数:11,代码来源:test_connection.py

示例4: test_connect

    def test_connect(self):
        """Ensure that the connect() method works properly."""
        connect('mongoenginetest')

        conn = get_connection()
        self.assertIsInstance(conn, pymongo.mongo_client.MongoClient)

        db = get_db()
        self.assertIsInstance(db, pymongo.database.Database)
        self.assertEqual(db.name, 'mongoenginetest')

        connect('mongoenginetest2', alias='testdb')
        conn = get_connection('testdb')
        self.assertIsInstance(conn, pymongo.mongo_client.MongoClient)
开发者ID:MongoEngine,项目名称:mongoengine,代码行数:14,代码来源:test_connection.py

示例5: disconnect

def disconnect(alias=DEFAULT_CONNECTION_NAME):
    """ To disconnect pymongo connection.

    Copied from mongoengine/connection.py to fix a bug in mongoengine source code,
    ('disconnect' method is removed from pymongo MongoClient in latest version.)
    """
    global _connections
    global _dbs

    if alias in _connections:
        get_connection(alias=alias).close()
        del _connections[alias]
    if alias in _dbs:
        del _dbs[alias]
开发者ID:hspandher,项目名称:django-test-addons,代码行数:14,代码来源:utils.py

示例6: test_connect_in_mocking

    def test_connect_in_mocking(self):
        """Ensure that the connect() method works properly in mocking.
        """
        try:
            import mongomock
        except ImportError:
            raise SkipTest('you need mongomock installed to run this testcase')

        connect('mongoenginetest', host='mongomock://localhost')
        conn = get_connection()
        self.assertTrue(isinstance(conn, mongomock.MongoClient))

        connect('mongoenginetest2', host='mongomock://localhost', alias='testdb')
        conn = get_connection('testdb')
        self.assertTrue(isinstance(conn, mongomock.MongoClient))
开发者ID:DavidBord,项目名称:mongoengine,代码行数:15,代码来源:test_connection.py

示例7: test_connect

    def test_connect(self):
        """Ensure that the connect() method works properly.
        """
        connect('mongoenginetest')

        conn = get_connection()
        self.assertTrue(isinstance(conn, pymongo.connection.Connection))

        db = get_db()
        self.assertTrue(isinstance(db, pymongo.database.Database))
        self.assertEqual(db.name, 'mongoenginetest')

        connect('mongoenginetest2', alias='testdb')
        conn = get_connection('testdb')
        self.assertTrue(isinstance(conn, pymongo.connection.Connection))
开发者ID:deignacio,项目名称:mongoengine,代码行数:15,代码来源:connection.py

示例8: test_sharing_connections

    def test_sharing_connections(self):
        """Ensure that connections are shared when the connection settings are exactly the same
        """
        connect('mongoenginetests', alias='testdb1')
        expected_connection = get_connection('testdb1')

        connect('mongoenginetests', alias='testdb2')
        actual_connection = get_connection('testdb2')

        # Handle PyMongo 3+ Async Connection
        if IS_PYMONGO_3:
            # Ensure we are connected, throws ServerSelectionTimeoutError otherwise.
            # Purposely not catching exception to fail test if thrown.
            expected_connection.server_info()

        self.assertEqual(expected_connection, actual_connection)
开发者ID:OJFord,项目名称:mongoengine,代码行数:16,代码来源:test_connection.py

示例9: 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

示例10: test_register_connection_defaults

    def test_register_connection_defaults(self):
        """Ensure that defaults are used when the host and port are None.
        """
        register_connection('testdb', 'mongoenginetest', host=None, port=None)

        conn = get_connection('testdb')
        self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient))
开发者ID:ThisGuyCodes,项目名称:mongoengine,代码行数:7,代码来源:test_connection.py

示例11: 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

示例12: setUp

 def setUp(self):
     # データベースに接続
     addr = '127.0.0.1'
     port = 27017
     connect('test', host=addr, port=port)
     self.conn = get_connection()
     self.db = get_db()
开发者ID:JFK,项目名称:python-tornado-site-template,代码行数:7,代码来源:test_user.py

示例13: test_connect_uri

    def test_connect_uri(self):
        """Ensure that the connect() method works properly with URIs."""
        c = connect(db='mongoenginetest', alias='admin')
        c.admin.system.users.remove({})
        c.mongoenginetest.system.users.remove({})

        c.admin.add_user("admin", "password")
        c.admin.authenticate("admin", "password")
        c.mongoenginetest.add_user("username", "password")

        if not IS_PYMONGO_3:
            self.assertRaises(
                MongoEngineConnectionError, connect, 'testdb_uri_bad',
                host='mongodb://test:[email protected]'
            )

        connect("testdb_uri", host='mongodb://username:[email protected]/mongoenginetest')

        conn = get_connection()
        self.assertTrue(isinstance(conn, pymongo.mongo_client.MongoClient))

        db = get_db()
        self.assertTrue(isinstance(db, pymongo.database.Database))
        self.assertEqual(db.name, 'mongoenginetest')

        c.admin.system.users.remove({})
        c.mongoenginetest.system.users.remove({})
开发者ID:mikeckennedy,项目名称:mongoengine,代码行数:27,代码来源:test_connection.py

示例14: get_mongodb_version

def get_mongodb_version():
    """Return the version of the connected mongoDB (first 2 digits)

    :return: tuple(int, int)
    """
    version_list = get_connection().server_info()['versionArray'][:2]     # e.g: (3, 2)
    return tuple(version_list)
开发者ID:MongoEngine,项目名称:mongoengine,代码行数:7,代码来源:mongodb_support.py

示例15: test_connect_uri

    def test_connect_uri(self):
        """Ensure that the connect() method works properly with URIs."""
        c = connect(db='mongoenginetest', alias='admin')
        c.admin.system.users.delete_many({})
        c.mongoenginetest.system.users.delete_many({})

        c.admin.command("createUser", "admin", pwd="password", roles=["root"])
        c.admin.authenticate("admin", "password")
        c.admin.command("createUser", "username", pwd="password", roles=["dbOwner"])

        if not IS_PYMONGO_3:
            self.assertRaises(
                MongoEngineConnectionError, connect, 'testdb_uri_bad',
                host='mongodb://test:[email protected]'
            )

        connect("testdb_uri", host='mongodb://username:[email protected]/mongoenginetest')

        conn = get_connection()
        self.assertIsInstance(conn, pymongo.mongo_client.MongoClient)

        db = get_db()
        self.assertIsInstance(db, pymongo.database.Database)
        self.assertEqual(db.name, 'mongoenginetest')

        c.admin.system.users.delete_many({})
        c.mongoenginetest.system.users.delete_many({})
开发者ID:MongoEngine,项目名称:mongoengine,代码行数:27,代码来源:test_connection.py


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