def test_is_not_started(self):
        pipeline_instance = MagicMock()
        pipeline_instance.is_started = False

        dispatcher = TaskCommandDispatcher(engine_ver=1,
                                           taskflow_id=1,
                                           pipeline_instance=pipeline_instance,
                                           project_id=1)
        result = dispatcher.render_current_constants_v1()
        self.assertEqual(
            result,
            {
                "result": False,
                "data": None,
                "code": err_code.INVALID_OPERATION.code,
                "message": "task is not running"
            },
        )
    def test_normal(self):
        self.maxDiff = None
        pipeline_instance = MagicMock()
        pipeline_instance.is_started = True
        pipeline_instance.is_finished = False
        pipeline_instance.is_revoked = False
        pipeline_instance.instance_id = "instance_id_token"
        pipeline_model = MagicMock()

        class VariableMagicMock(MagicMock, Variable):
            pass

        class TestTaskContext(TaskContext):
            def __init__(self):
                self.value = "TestTaskContext"

        class TestValueVar(Variable):
            def __init__(self, value):
                self.value = value

        var1 = TestValueVar(value=TestTaskContext())

        var2 = VariableMagicMock()
        var2.get = MagicMock(return_value="val2")

        var4 = VariableMagicMock()
        var4.get = MagicMock(side_effect=Exception)

        pipeline_model.process.root_pipeline.context.variables = {
            "k1": var1,
            "k2": var2,
            "k4": var4,
            "k5": "v5",
            "k6": 6,
        }

        pipeline_model_cls = MagicMock()
        pipeline_model_cls.objects.get = MagicMock(return_value=pipeline_model)

        with mock.patch(TASKFLOW_DISPATCHERS_TASK_PIPELINE_MODEL,
                        pipeline_model_cls):
            dispatcher = TaskCommandDispatcher(
                engine_ver=1,
                taskflow_id=1,
                pipeline_instance=pipeline_instance,
                project_id=1)
            result = dispatcher.render_current_constants_v1()

        pipeline_model_cls.objects.get.assert_called_once_with(
            id=pipeline_instance.instance_id)
        self.assertEqual(
            result,
            {
                "result":
                True,
                "data": [
                    {
                        "key": "k1",
                        "value": {
                            "value": "TestTaskContext"
                        }
                    },
                    {
                        "key": "k2",
                        "value": "val2"
                    },
                    {
                        "key": "k4",
                        "value": "[ERROR]value resolve error"
                    },
                    {
                        "key": "k5",
                        "value": "v5"
                    },
                    {
                        "key": "k6",
                        "value": 6
                    },
                ],
                "code":
                err_code.SUCCESS.code,
                "message":
                "",
            },
        )