def test_service_description(self):
        rpc = RpcProcessor()

        self.assertEqual(rpc.describe_service(), {
            'name': '',
            'description': '',
            'version': '',
            'custom_fields': {}
        })

        rpc.set_description("Example RPC Service",
                            "This is an example service for ReflectRPC", "1.0",
                            {
                                'field1': 'test',
                                'field2': 42
                            })

        expected_desc = {
            'name': 'Example RPC Service',
            'description': 'This is an example service for ReflectRPC',
            'version': '1.0',
            'custom_fields': {
                'field1': 'test',
                'field2': 42
            }
        }

        self.assertEqual(rpc.describe_service(), expected_desc)
    def test_service_description(self):
        rpc = RpcProcessor()

        self.assertEqual(rpc.describe_service(), {'name': '', 'description': '',
            'version': '', 'custom_fields': {}})

        rpc.set_description("Example RPC Service",
                "This is an example service for ReflectRPC", "1.0",
                {'field1': 'test', 'field2': 42})

        expected_desc = {'name': 'Example RPC Service',
                'description': 'This is an example service for ReflectRPC',
                'version': '1.0', 'custom_fields': {'field1': 'test', 'field2': 42}
        }

        self.assertEqual(rpc.describe_service(), expected_desc)
    def calc_result(value):
        raise JsonRpcError("You wanted an error, here you have it!")

    return task.deferLater(reactor, 0.1, calc_result, None)


def deferred_internal_error():
    def calc_result(value):
        return 56 / 0

    return task.deferLater(reactor, 0.1, calc_result, None)


jsonrpc = RpcProcessor()
jsonrpc.set_description(
    "Concurrency Example RPC Service",
    "This service demonstrates concurrency with the Twisted Server", "1.0")

slow_func = reflectrpc.RpcFunction(slow_operation, 'slow_operation',
                                   'Calculate ultimate answer', 'int',
                                   'Ultimate answer')
jsonrpc.add_function(slow_func)

fast_func = reflectrpc.RpcFunction(
    fast_operation, 'fast_operation',
    'Calculate fast approximation of the ultimate answer', 'int',
    'Approximation of the ultimate answer')
jsonrpc.add_function(fast_func)

error_func = reflectrpc.RpcFunction(
    deferred_error, 'deferred_error',
Exemple #4
0
    return 41

def deferred_error():
    def calc_result(value):
        raise JsonRpcError("You wanted an error, here you have it!")

    return task.deferLater(reactor, 0.1, calc_result, None)

def deferred_internal_error():
    def calc_result(value):
        return 56 / 0

    return task.deferLater(reactor, 0.1, calc_result, None)

jsonrpc = RpcProcessor()
jsonrpc.set_description("Concurrency Example RPC Service",
        "This service demonstrates concurrency with the Twisted Server", "1.0")

slow_func = reflectrpc.RpcFunction(slow_operation, 'slow_operation', 'Calculate ultimate answer',
        'int', 'Ultimate answer')
jsonrpc.add_function(slow_func)

fast_func = reflectrpc.RpcFunction(fast_operation, 'fast_operation',
        'Calculate fast approximation of the ultimate answer',
        'int', 'Approximation of the ultimate answer')
jsonrpc.add_function(fast_func)

error_func = reflectrpc.RpcFunction(deferred_error, 'deferred_error', 'Raise a JsonRpcError from a deferred function',
        'int', 'Nothing of interest')
jsonrpc.add_function(error_func)

internal_error_func = reflectrpc.RpcFunction(deferred_internal_error, 'deferred_internal_error',
Exemple #5
0
    conn, d = get_db_connection()

    d.addCallback(lambda _: conn.runOperation(
        "DELETE FROM jsonstore WHERE obj_name=%s", (name, )))

    def return_result(data):
        conn.close()
        return True

    return d


# Create service object
jsonrpc = RpcProcessor()
jsonrpc.set_description(
    "JSON Store Service",
    "JSON-RPC service for storing JSON objects in a PostgreSQL database",
    reflectrpc.version)

# Register functions
get_object_func = RpcFunction(get_object, 'get_object',
                              'Gets a JSON object by its UUID', 'hash',
                              'JSON object')
get_object_func.add_param('string', 'uuid',
                          'UUID of the JSON object to retrieve')
get_object_func.require_rpcinfo()
jsonrpc.add_function(get_object_func)

get_object_by_name_func = RpcFunction(get_object_by_name, 'get_object_by_name',
                                      'Gets a JSON object by its name', 'hash',
                                      'JSON object')
get_object_by_name_func.add_param('string', 'name',
Exemple #6
0
def delete_object_by_name(rpcinfo, name):
    conn, d = get_db_connection()

    d.addCallback(lambda _: conn.runOperation("DELETE FROM jsonstore WHERE obj_name=%s", (name, )))

    def return_result(data):
        conn.close()
        return True

    return d


# Create service object
jsonrpc = RpcProcessor()
jsonrpc.set_description("JSON Store Service",
        "JSON-RPC service for storing JSON objects in a PostgreSQL database",
        reflectrpc.version)

# Register functions
get_object_func = RpcFunction(get_object, 'get_object', 'Gets a JSON object by its UUID',
        'hash', 'JSON object')
get_object_func.add_param('string', 'uuid', 'UUID of the JSON object to retrieve')
get_object_func.require_rpcinfo()
jsonrpc.add_function(get_object_func)

get_object_by_name_func = RpcFunction(get_object_by_name, 'get_object_by_name', 'Gets a JSON object by its name', 'hash', 'JSON object')
get_object_by_name_func.add_param('string', 'name', 'Name of the JSON object to retrieve')
get_object_by_name_func.require_rpcinfo()
jsonrpc.add_function(get_object_by_name_func)

find_objects_func = RpcFunction(find_objects, 'find_objects', 'Finds JSON objects which match a filter', 'array<hash>', 'List of matching JSON object')