def test_do_set_request_no_specifier():
    print("start test")
    an_endpoint = dripline.core.Endpoint("hello")
    the_node = scarab.ParamNode()
    the_node["values"] = scarab.ParamArray()
    the_node["values"].push_back(scarab.ParamValue("a_better_endpoint"))
    a_set_request = dripline.core.MsgRequest.create(the_node,
                                                    dripline.core.op_t.set,
                                                    "hey")
    correct_error = False
    try:
        a_reply = an_endpoint.do_set_request(a_set_request)
    except dripline.core.ThrowReply as e:
        correct_error = True
    assert (correct_error)
def test_do_set_request_invalid_specifier():
    an_endpoint = dripline.core.Endpoint("an_endpoint")
    the_node = scarab.ParamNode()
    the_node["values"] = scarab.ParamArray()
    the_node["values"].push_back(scarab.ParamValue("a_better_endpoint"))
    a_set_request = dripline.core.MsgRequest.create(the_node,
                                                    dripline.core.op_t.set,
                                                    "hey", "namee",
                                                    "a_receiver")
    correct_error = False
    try:
        a_reply = an_endpoint.do_set_request(a_set_request)
    except dripline.core.ThrowReply as e:
        correct_error = True
        print('content of error:\n{}'.format(dir(e)))
    assert (correct_error)
Example #3
0
 def do_get_request(self, a_request_message):
     logger.info("in get_request")
     a_specifier =  a_request_message.specifier.to_string()
     if (a_specifier):
         logger.debug("has specifier")
         try:
             logger.debug(f"specifier is: {a_specifier}")
             an_attribute = getattr(self, a_specifier)
             logger.debug(f"attribute '{a_specifier}' value is [{an_attribute}]")
             the_node = scarab.ParamNode()
             the_node["values"] = scarab.ParamArray()
             the_node["values"].push_back(scarab.ParamValue(an_attribute))
             return a_request_message.reply(payload=the_node)
         except AttributeError as this_error:
             raise ThrowReply('service_error_invalid_specifier', f"endpoint {self.name} has no attribute {a_specifier}, unable to get")
     else:
         logger.debug('no specifier')
         the_value = self.on_get()
         return a_request_message.reply(payload=scarab.to_param(the_value))
def test_do_set_request_valid_specifier():
    value1 = "an_endpoint"
    value2 = "a_better_endpoint"

    ## the endpoint base class doesn't have any settable members, create one:
    class EndpointWithMember(dripline.core.Endpoint):
        a_value = value1

    an_endpoint = EndpointWithMember("an_endpoint")
    the_node = scarab.ParamNode()
    the_node["values"] = scarab.ParamArray()
    the_node["values"].push_back(scarab.ParamValue(value2))
    a_set_request = dripline.core.MsgRequest.create(the_node,
                                                    dripline.core.op_t.set,
                                                    "hey", "a_value",
                                                    "a_receiver")
    a_reply = an_endpoint.do_set_request(a_set_request)
    assert (isinstance(a_reply, dripline.core.MsgReply))
    assert (a_reply.return_code == 0)
    assert (a_reply.correlation_id == a_set_request.correlation_id)
    print(an_endpoint.name)
    assert (an_endpoint.a_value == value2)
def test_do_cmd_request_valid_specifier():
    class AnotherEndpoint(dripline.core.Endpoint):
        def __init__(self, name):
            dripline.core.Endpoint.__init__(self, name)

        def a_method(self, n1, n2):
            return n1 + n2

    an_endpoint = AnotherEndpoint("an_endpoint")
    the_node = scarab.ParamNode()
    the_node["values"] = scarab.ParamArray()
    n1, n2 = 10, 13
    the_node["values"].push_back(scarab.ParamValue(n1))
    the_node["values"].push_back(scarab.ParamValue(n2))
    a_cmd_request = dripline.core.MsgRequest.create(the_node,
                                                    dripline.core.op_t.cmd,
                                                    "hey", "a_method",
                                                    "a_receiver")
    a_reply = an_endpoint.do_cmd_request(a_cmd_request)
    assert (isinstance(a_reply, dripline.core.MsgReply))
    assert (a_reply.return_code == 0)
    assert (a_reply.correlation_id == a_cmd_request.correlation_id)
    assert (a_reply.payload.to_python() == n1 + n2)
def test_request_create_nondefault():
    a_payload = scarab.ParamNode()
    a_payload.add("p1", scarab.ParamValue(1))
    a_payload.add("p2", scarab.ParamValue(2))
    a_msg_op = _dripline.core.op_t.get
    a_routing_key = "hey"
    a_specifier = "heyy.1"
    a_reply_to = "a_receiver"
    a_request = _dripline.core.MsgRequest.create(a_payload, a_msg_op,
                                                 a_routing_key, a_specifier,
                                                 a_reply_to)
    assert (isinstance(a_request, _dripline.core.MsgRequest))
    assert (a_request.is_request())
    assert (not a_request.is_reply())
    assert (not a_request.is_alert())
    assert (a_request.lockout_key_valid)
    assert (a_request.payload.is_node())
    assert (a_request.payload.count("p1") == 1)
    assert (a_request.message_operation == a_msg_op)
    assert (a_request.routing_key == a_routing_key)
    assert (a_request.specifier.to_string() == a_specifier)
    assert (a_request.reply_to == a_reply_to)
    assert (a_request.encoding.name == "json")
    assert (len(a_request.correlation_id) == 36)