예제 #1
0
    def test_raise(self):
        taskflow = TaskFlowInstance()
        taskflow.id = 1
        taskflow.engine_ver = 2
        taskflow.has_node = MagicMock(return_value=True)
        dispatcher = MagicMock()
        dispatcher.dispatch = MagicMock(side_effect=Exception("exception"))
        dispatcher_init = MagicMock(return_value=dispatcher)

        action = "action"
        node_id = "node_id"
        username = "******"

        with patch(TASKFLOW_MODEL_NODE_CMD_DISPATCHER, dispatcher_init):
            result = taskflow.nodes_action(action=action,
                                           node_id=node_id,
                                           username=username)

        dispatcher_init.assert_called_once_with(engine_ver=taskflow.engine_ver,
                                                node_id=node_id,
                                                taskflow_id=1)
        dispatcher.dispatch.assert_called_once_with(action, username)
        self.assertEqual(
            result,
            {
                "result": False,
                "message":
                "task[id=1] node[id=node_id] action failed: exception",
                "code": err_code.UNKNOWN_ERROR.code,
            },
        )
예제 #2
0
    def test_node_does_not_exist(self):
        taskflow = TaskFlowInstance()
        taskflow.id = 1
        taskflow.has_node = MagicMock(return_value=False)

        detail = taskflow.nodes_action(action="action",
                                       node_id="node_id",
                                       username="******")
        self.assertFalse(detail["result"])
        self.assertEqual(detail["code"], err_code.REQUEST_PARAM_INVALID.code)
예제 #3
0
    def test_success(self):
        taskflow = TaskFlowInstance()
        taskflow.id = 1
        taskflow.engine_ver = 2
        taskflow.has_node = MagicMock(return_value=True)
        dispatcher = MagicMock()
        dispatch_return = {"result": True, "data": {"data": "data"}}
        dispatcher.dispatch = MagicMock(return_value=dispatch_return)
        dispatcher_init = MagicMock(return_value=dispatcher)

        action = "action"
        node_id = "node_id"
        username = "******"

        with patch(TASKFLOW_MODEL_NODE_CMD_DISPATCHER, dispatcher_init):
            result = taskflow.nodes_action(action=action,
                                           node_id=node_id,
                                           username=username)

        dispatcher_init.assert_called_once_with(engine_ver=taskflow.engine_ver,
                                                node_id=node_id,
                                                taskflow_id=1)
        dispatcher.dispatch.assert_called_once_with(action, username)
        self.assertEqual(result, dispatch_return)