def test_exception_conversion_unknown_index(): def raise_unknown_index(): raise exceptions.UnknownIndex('foo') with pytest.raises(errors.UnknownIndexError) as ute: errors.trap_error(lambda: raise_unknown_index()) assert ute.value.message == 'Unknown index'
def test_exception_conversion_elasticsearch_error(): def raise_elasticsearch_error(): raise exceptions.ElasticsearchError('foo') with pytest.raises(errors.ElasticsearchServerError) as ute: errors.trap_error(lambda: raise_elasticsearch_error()) assert ute.value.message == 'Elasticsearch server error'
def test_exception_conversion_user_profile(): def raise_user_profile_error(): raise exceptions.UserProfileError('foo', 'bar') with pytest.raises(errors.UserProfileServiceError) as ute: errors.trap_error(lambda: raise_user_profile_error()) assert ute.value.message == 'User profile service error' assert str( ute.value) == 'User profile service error\nResponse: bar\nURL: foo'
def test_exception_conversion_auth_error(): def raise_auth_error(): og_error = {'error': {'message': 'foo'}} raise exceptions.AuthError(og_error, 'bar') with pytest.raises(errors.AuthorizationError) as ute: errors.trap_error(lambda: raise_auth_error()) assert ute.value.message == 'Auth error' assert ute.value.error['message'] == 'foo'
def search_types(params, meta): if isinstance(params, list) and len(params) == 1: params = params[0] start = time.time() query = convert_params.search_types(params) search_result = trap_error(lambda: search(query, meta)) result = convert_result.search_types(search_result) logger.debug(f'Finished search_types in {time.time() - start}s') return [result]
def get_objects(params, meta): # KBase convention is to wrap params in an array if isinstance(params, list) and len(params) == 1: params = params[0] start = time.time() query = convert_params.get_objects(params) search_result = trap_error(lambda: search(query, meta)) result = convert_result.get_objects(params, search_result, meta) logger.debug(f'Finished get_objects in {time.time() - start}s') return [result]