def test_add_event(self): event = events_pb2.Event(event_type="add_event") mock_context_manager = Mock() handler = TpEventAddHandler(mock_context_manager) request = state_context_pb2.TpEventAddRequest(event=event).SerializeToString() response = handler.handle("test_conn_id", request) self.assertEqual(HandlerStatus.RETURN, response.status)
def handle(self, connection_id, message_content): add_event_request = state_context_pb2.TpEventAddRequest() add_event_request.ParseFromString(message_content) success = self._context_manager.add_execution_event( add_event_request.context_id, add_event_request.event) ack = state_context_pb2.TpEventAddResponse() if success: ack.status = ack.OK else: ack.status = ack.ERROR return HandlerResult( status=HandlerStatus.RETURN, message_out=ack, message_type=validator_pb2.Message.TP_EVENT_ADD_RESPONSE)