def test_enable_sharding(mongo_host, arctic, mongo_server, user_library, user_library_name): c = mongo_server.api with patch.object(c, 'admin') as admin: with patch('pymongo.MongoClient', return_value=c) as mc: run_as_main(mes.main, '--host', mongo_host, '--library', user_library_name) assert mc.call_args_list == [call(get_mongodb_uri(mongo_host))] assert admin.command.call_args_list == [call('buildinfo', read_preference=Primary()), call('enablesharding', 'arctic_' + getpass.getuser()), call('shardCollection', 'arctic_' + user_library_name, key={'symbol': 'hashed'})]
def test_enable_sharding(mongo_host, arctic, mongo_server, user_library, user_library_name): c = mongo_server.api with patch.object(c, 'admin') as admin: with patch('pymongo.MongoClient', return_value=c) as mc: run_as_main(mes.main, '--host', mongo_host, '--library', user_library_name) assert mc.call_args_list == [call(get_mongodb_uri(mongo_host))] assert len(admin.command.call_args_list) == 3 assert call('buildinfo', read_preference=Primary(), session=None) in admin.command.call_args_list or call('buildinfo', read_preference=Primary()) in admin.command.call_args_list assert call('shardCollection', 'arctic_' + user_library_name, key={'symbol': 'hashed'}) in admin.command.call_args_list assert call('enablesharding', 'arctic_' + getpass.getuser()) in admin.command.call_args_list
def test_enable_sharding_already_on_db(mongo_host, arctic, mongodb, user_library, user_library_name): c = mongodb with patch.object(c, 'admin') as admin: admin.command = Mock(return_value=[OperationFailure("failed: already enabled"), None]) with patch('pymongo.MongoClient', return_value=c) as mc: run_as_main(mes.main, '--host', mongo_host, '--library', user_library_name) assert mc.call_args_list == [call(get_mongodb_uri(mongo_host))] assert admin.command.call_args_list == [call('buildinfo', read_preference=Primary()), call('enablesharding', 'arctic_' + getpass.getuser()), call('shardCollection', 'arctic_' + user_library_name, key={'symbol': 1})]
def test_enable_sharding_already_on_db(mongo_host, arctic, mongo_server, user_library, user_library_name): c = mongo_server.api with patch.object(c, 'admin') as admin: admin.command = Mock( return_value=[OperationFailure("failed: already enabled"), None]) with patch('pymongo.MongoClient', return_value=c) as mc: run_as_main(mes.main, '--host', mongo_host, '--library', user_library_name) assert mc.call_args_list == [call(get_mongodb_uri(mongo_host))] assert admin.command.call_args_list == [ call('buildinfo', read_preference=Primary()), call('enablesharding', 'arctic_' + getpass.getuser()), call('shardCollection', 'arctic_' + user_library_name, key={'symbol': 1}) ]
def test_get_mongodb_uri_hook(): resolver = Mock() resolver.return_value = sentinel.result register_resolve_mongodb_hook(resolver) assert get_mongodb_uri(sentinel.host) == sentinel.result assert resolver.call_args_list == [call(sentinel.host)]