Example #1
0
    def test_node_does_not_exist(self):
        taskflow = TaskFlowInstance()
        taskflow.id = 1
        taskflow.has_node = MagicMock(return_value=False)

        detail = taskflow.callback(node_id="node_id", data="data")
        self.assertFalse(detail["result"])
        self.assertEqual(detail["code"], err_code.REQUEST_PARAM_INVALID.code)
    def test_callback(self):
        instance = TaskFlowInstance()

        objects_callback_return = {'result': True, 'message': 'success'}

        with mock.patch(TASKINSTANCE_OBJECTS_CALLBACK, MagicMock(return_value=objects_callback_return)):
            with mock.patch(TASKINSTANCE_HAS_NODE, MagicMock(return_value=False)):
                result = instance.callback('act_id', 'data')
                self.assertFalse(result['result'])
                self.assertTrue('message' in result)
                TaskFlowInstance.objects.callback.assert_not_called()

            with mock.patch(TASKINSTANCE_HAS_NODE, MagicMock(return_value=True)):
                result = instance.callback('act_id', 'data')
                self.assertTrue(result['result'])
                self.assertTrue('message' in result)
                TaskFlowInstance.objects.callback.assert_called_once_with('act_id', 'data')
Example #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)

        node_id = "node_id"
        data = "data"
        version = "version"

        with patch(TASKFLOW_MODEL_NODE_CMD_DISPATCHER, dispatcher_init):
            result = taskflow.callback(node_id=node_id, data=data, version=version)

        dispatcher_init.assert_called_once_with(engine_ver=taskflow.engine_ver, node_id=node_id, taskflow_id=1)
        dispatcher.dispatch.assert_called_once_with(command="callback", operator="", data=data, version=version)
        self.assertEqual(result, dispatch_return)