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)
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)