Example #1
0
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'
Example #2
0
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'
Example #3
0
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'
Example #4
0
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'
Example #5
0
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]
Example #6
0
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]