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


Python mongo_client.MongoClient方法代码示例

本文整理汇总了Python中pymongo.mongo_client.MongoClient方法的典型用法代码示例。如果您正苦于以下问题:Python mongo_client.MongoClient方法的具体用法?Python mongo_client.MongoClient怎么用?Python mongo_client.MongoClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.mongo_client的用法示例。


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

示例1: test_arctic_lazy_init_ssl_true

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_lazy_init_ssl_true():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
            patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
            patch('arctic._cache.Cache._is_not_expired', return_value=True), \
            patch('arctic.arctic.get_auth', autospec=True) as ga:
        store = Arctic('cluster', ssl=True)
        assert not mc.called
        # do something to trigger lazy arctic init
        store.list_libraries()
        assert mc.called
        assert len(mc.mock_calls) == 1
        assert mc.mock_calls[0] == call(connectTimeoutMS=2000,
                                        host='cluster',
                                        maxPoolSize=4,
                                        serverSelectionTimeoutMS=30000,
                                        socketTimeoutMS=600000,
                                        ssl=True) 
开发者ID:man-group,项目名称:arctic,代码行数:19,代码来源:test_arctic.py

示例2: test_arctic_auth

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_auth():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
        patch('arctic.arctic.mongo_retry', autospec=True), \
         patch('arctic._cache.Cache._is_not_expired', return_value=True), \
         patch('arctic.arctic.get_auth', autospec=True) as ga:
            ga.return_value = Credential('db', 'admin_user', 'admin_pass')
            store = Arctic('cluster')
            # do something to trigger lazy arctic init
            store.list_libraries()
            ga.assert_called_once_with('cluster', 'arctic', 'admin')
            store._adminDB.authenticate.assert_called_once_with('admin_user', 'admin_pass')
            ga.reset_mock()

            # Get a 'missing' library
            with pytest.raises(LibraryNotFoundException):
                with patch('arctic.arctic.ArcticLibraryBinding.get_library_type', return_value=None, autospec=True):
                    ga.return_value = Credential('db', 'user', 'pass')
                    store._conn['arctic_jblackburn'].name = 'arctic_jblackburn'
                    store['jblackburn.library']

            # Creating the library will have attempted to auth against it
            ga.assert_called_once_with('cluster', 'arctic', 'arctic_jblackburn')
            store._conn['arctic_jblackburn'].authenticate.assert_called_once_with('user', 'pass') 
开发者ID:man-group,项目名称:arctic,代码行数:25,代码来源:test_arctic.py

示例3: test_arctic_auth_custom_app_name

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_auth_custom_app_name():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
        patch('arctic.arctic.mongo_retry', autospec=True), \
         patch('arctic._cache.Cache._is_not_expired', return_value=True), \
         patch('arctic.arctic.get_auth', autospec=True) as ga:
            ga.return_value = Credential('db', 'admin_user', 'admin_pass')
            store = Arctic('cluster', app_name=sentinel.app_name)
            # do something to trigger lazy arctic init
            store.list_libraries()
            assert ga.call_args_list == [call('cluster', sentinel.app_name, 'admin')]
            ga.reset_mock()

            # Get a 'missing' library
            with pytest.raises(LibraryNotFoundException):
                with patch('arctic.arctic.ArcticLibraryBinding.get_library_type', return_value=None, autospec=True):
                    ga.return_value = Credential('db', 'user', 'pass')
                    store._conn['arctic_jblackburn'].name = 'arctic_jblackburn'
                    store['jblackburn.library']

            # Creating the library will have attempted to auth against it
            assert ga.call_args_list == [call('cluster', sentinel.app_name, 'arctic_jblackburn')] 
开发者ID:man-group,项目名称:arctic,代码行数:23,代码来源:test_arctic.py

示例4: test_arctic_connect_with_environment_name

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_connect_with_environment_name():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
         patch('arctic.arctic.mongo_retry', autospec=True) as ar, \
         patch('arctic.arctic.get_auth', autospec=True), \
         patch('arctic._cache.Cache._is_not_expired', return_value=True), \
         patch('arctic.arctic.get_mongodb_uri') as gmfe:
            store = Arctic('live', socketTimeoutMS=sentinel.socket_timeout,
                                 connectTimeoutMS=sentinel.connect_timeout,
                                 serverSelectionTimeoutMS=sentinel.select_timeout)
            # do something to trigger lazy arctic init
            store.list_libraries()
    assert gmfe.call_args_list == [call('live')]
    assert mc.call_args_list == [call(host=gmfe.return_value, maxPoolSize=4,
                                      socketTimeoutMS=sentinel.socket_timeout,
                                      connectTimeoutMS=sentinel.connect_timeout,
                                      serverSelectionTimeoutMS=sentinel.select_timeout)] 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_arctic.py

示例5: test_initialize_library_too_many_ns

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_initialize_library_too_many_ns():
    self = create_autospec(Arctic)
    self._conn = create_autospec(MongoClient)
    self._cache = create_autospec(Cache)
    lib = create_autospec(ArcticLibraryBinding)
    lib.database_name = sentinel.db_name
    self._conn.__getitem__.return_value.list_collection_names.return_value = [x for x in six.moves.xrange(5001)]
    lib_type = Mock()
    with pytest.raises(ArcticException) as e:
        with patch.dict('arctic.arctic.LIBRARY_TYPES', {sentinel.lib_type: lib_type}), \
             patch('arctic.arctic.ArcticLibraryBinding', return_value=lib, autospec=True) as ML:
            Arctic.initialize_library(self, sentinel.lib_name, sentinel.lib_type, thing=sentinel.thing)
    assert self._conn.__getitem__.call_args_list == [call(sentinel.db_name),
                                                     call(sentinel.db_name)]
    assert lib_type.initialize_library.call_count == 0
    assert 'Too many namespaces 5001, not creating: sentinel.lib_name' in str(e.value) 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_arctic.py

示例6: test_initialize_library_with_list_coll_names

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_initialize_library_with_list_coll_names():
    self = create_autospec(Arctic)
    self._conn = create_autospec(MongoClient)
    self._cache = create_autospec(Cache)
    lib = create_autospec(ArcticLibraryBinding)
    lib.database_name = sentinel.db_name
    lib.get_quota.return_value = None
    self._conn.__getitem__.return_value.list_collection_names.return_value = [x for x in six.moves.xrange(5001)]
    lib_type = Mock()
    with patch.dict('arctic.arctic.LIBRARY_TYPES', {sentinel.lib_type: lib_type}), \
         patch('arctic.arctic.ArcticLibraryBinding', return_value=lib, autospec=True) as ML:
        Arctic.initialize_library(self, sentinel.lib_name, sentinel.lib_type, thing=sentinel.thing, check_library_count=False)
    assert ML.call_args_list == [call(self, sentinel.lib_name)]
    assert ML.return_value.set_library_type.call_args_list == [call(sentinel.lib_type)]
    assert ML.return_value.set_quota.call_args_list == [call(10 * 1024 * 1024 * 1024)]
    assert lib_type.initialize_library.call_args_list == [call(ML.return_value, thing=sentinel.thing)] 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:test_arctic.py

示例7: test_ArcticLibraryBinding_db

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_ArcticLibraryBinding_db():
    arctic = create_autospec(Arctic)
    arctic._conn = create_autospec(MongoClient)
    alb = ArcticLibraryBinding(arctic, "sentinel.library")
    with patch.object(alb, '_auth') as _auth:
        # connection is cached during __init__
        alb._db
        assert _auth.call_count == 0

        # Change the arctic connection
        arctic._conn = create_autospec(MongoClient)
        alb._db
        assert _auth.call_count == 1

        # connection is still cached
        alb._db
        assert _auth.call_count == 1 
开发者ID:man-group,项目名称:arctic,代码行数:19,代码来源:test_arctic.py

示例8: create

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def create(client, opts):
        """Create a _CommandEncyptor for a client.

        :Parameters:
          - `client`: The encrypted MongoClient.
          - `opts`: The encrypted client's :class:`AutoEncryptionOpts`.

        :Returns:
          A :class:`_CommandEncrypter` for this client.
        """
        key_vault_client = opts._key_vault_client or client
        db, coll = opts._key_vault_namespace.split('.', 1)
        key_vault_coll = key_vault_client[db][coll]

        mongocryptd_client = MongoClient(
            opts._mongocryptd_uri, connect=False,
            serverSelectionTimeoutMS=_MONGOCRYPTD_TIMEOUT_MS)

        io_callbacks = _EncryptionIO(
            client, key_vault_coll, mongocryptd_client, opts)
        return _Encrypter(io_callbacks, opts) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:encryption.py

示例9: launch

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def launch():
    # Default MongoClient params are:
    # w=1  perform a write acknowledgement only in primary
    # j=False the driver does not add j to the getlasterror command
    # fsync=False the server does not add Sync to disk. to the getlasterror command
    mongo_connection = MongoClient(BII_MONGO_URI, max_pool_size=BII_MAX_MONGO_POOL_SIZE)
    migration_store = MigrationStore(mongo_connection)
    server_store = MongoServerStore(mongo_connection)
    biiout = OutputStream()
    manager = MigrationManager(migration_store, SERVER_MIGRATIONS, biiout)

    # Pass in kwargs all variables migrations can need
    n1 = time.time()
    manager.migrate(server_store=server_store)
    n2 = time.time()
    biiout.info('All took %s seconds' % str(n2 - n1))

    # DO NOT REMOVE THIS PRINT NOR REPLACE WITH LOGGER, ITS A CONSOLE SCRIPT
    # INVOKED IN DEPLOYMENT PROCESS AND ITS NECESSARY IT PRINTS TO OUTPUT
    print biiout 
开发者ID:biicode,项目名称:bii-server,代码行数:22,代码来源:migration_launcher.py

示例10: test_arctic_lazy_init

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_lazy_init():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True) as mc, \
        patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
        patch('arctic._cache.Cache._is_not_expired', return_value=True), \
        patch('arctic.arctic.get_auth', autospec=True) as ga:
            store = Arctic('cluster')
            assert not mc.called
            # do something to trigger lazy arctic init
            store.list_libraries()
            assert mc.called 
开发者ID:man-group,项目名称:arctic,代码行数:12,代码来源:test_arctic.py

示例11: test_connection_passed_warning_raised

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_connection_passed_warning_raised():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True), \
         patch('arctic.arctic.mongo_retry', side_effect=lambda x: x, autospec=True), \
         patch('arctic._cache.Cache._is_not_expired', return_value=True), \
         patch('arctic.arctic.get_auth', autospec=True), \
         patch('arctic.arctic.logger') as lg:
        magic_mock = MagicMock(nodes={("host", "port")})
        store = Arctic(magic_mock, ssl=True)
        # Increment _pid to simulate forking the process
        store._pid += 1
        _ = store._conn
        assert lg.mock_calls[0] == call.warn('Forking process. Arctic was passed a pymongo connection during init, '
                                             'the new pymongo connection may have different parameters.') 
开发者ID:man-group,项目名称:arctic,代码行数:15,代码来源:test_arctic.py

示例12: test_arctic_repr

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_arctic_repr():
    with patch('pymongo.MongoClient', return_value=MagicMock(), autospec=True):
        with patch('arctic.arctic.mongo_retry', autospec=True):
            with patch('arctic.arctic.get_auth', autospec=True) as ga:
                ga.return_value = Credential('db', 'admin_user', 'admin_pass')
                store = Arctic('cluster')
                assert str(store) == repr(store) 
开发者ID:man-group,项目名称:arctic,代码行数:9,代码来源:test_arctic.py

示例13: test_initialize_library

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def test_initialize_library():
    self = create_autospec(Arctic)
    self._conn = create_autospec(MongoClient)
    self._cache = create_autospec(Cache)
    lib = create_autospec(ArcticLibraryBinding)
    lib.database_name = sentinel.db_name
    lib.get_quota.return_value = None
    lib_type = Mock()
    with patch.dict('arctic.arctic.LIBRARY_TYPES', {sentinel.lib_type: lib_type}), \
         patch('arctic.arctic.ArcticLibraryBinding', return_value=lib, autospec=True) as ML:
        Arctic.initialize_library(self, sentinel.lib_name, sentinel.lib_type, thing=sentinel.thing)
    assert ML.call_args_list == [call(self, sentinel.lib_name)]
    assert ML.return_value.set_library_type.call_args_list == [call(sentinel.lib_type)]
    assert ML.return_value.set_quota.call_args_list == [call(10 * 1024 * 1024 * 1024)]
    assert lib_type.initialize_library.call_args_list == [call(ML.return_value, thing=sentinel.thing)] 
开发者ID:man-group,项目名称:arctic,代码行数:17,代码来源:test_arctic.py

示例14: __init__

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def __init__(self, *args, **kwargs):
        warnings.warn('MongoReplicaSetClient is deprecated, use MongoClient'
                      ' to connect to a replica set',
                      DeprecationWarning, stacklevel=2)

        super(MongoReplicaSetClient, self).__init__(*args, **kwargs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:mongo_replica_set_client.py

示例15: _get_cachier_db_mongo_client

# 需要导入模块: from pymongo import mongo_client [as 别名]
# 或者: from pymongo.mongo_client import MongoClient [as 别名]
def _get_cachier_db_mongo_client():
    client = MongoClient(host=_TEST_HOST, port=_TEST_PORT, retryWrites=False)
    client.cachier_test.authenticate(
        name=_TEST_USERNAME,
        password=_TEST_PWD,
        mechanism='SCRAM-SHA-1'
    )
    return client 
开发者ID:shaypal5,项目名称:cachier,代码行数:10,代码来源:test_mongo_core.py


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