From 8d2032cf4b1d8eb6ddc8857bc4bc867e56dc1eee Mon Sep 17 00:00:00 2001 From: dengyh Date: Fri, 1 Aug 2025 10:34:18 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E6=9C=AC=E5=9C=B0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E8=A1=A5=E5=85=85=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=20--story=3D126242876"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 85372003466097dea7c114a61b30ec59a14087c3. --- .../collections/remote_plugin/v1_0_0.py | 15 +- .../collections/value_assign/v1_0_0.py | 2 +- bkflow/pipeline_plugins/test/__init__.py | 18 - .../test/components/collections/__init__.py | 0 .../collections/approve_test/__init__.py | 0 .../collections/approve_test/test_v1_0.py | 175 ------- .../collections/debug_plugin_test/__init__.py | 0 .../debug_plugin_test/test_v1_0_0.py | 51 -- .../collections/dmn_plugin_test/__init__.py | 0 .../dmn_plugin_test/test_v1_0_0.py | 125 ----- .../collections/http_test/__init__.py | 0 .../collections/http_test/test_v1_0.py | 441 ------------------ .../collections/remote_plugin/__init__.py | 0 .../collections/remote_plugin/test_plugin.py | 157 ------- .../collections/sleep_time_test/__init__.py | 0 .../sleep_time_test/test_legacy.py | 90 ---- .../collections/uniform_api_test/__init__.py | 0 .../uniform_api_test/test_v1_0_0.py | 127 ----- .../uniform_api_test/test_v2_0_0.py | 152 ------ .../collections/value_assign_test/__init__.py | 0 .../value_assign_test/test_v1_0_0.py | 100 ---- config/__init__.py | 5 +- 22 files changed, 14 insertions(+), 1444 deletions(-) delete mode 100644 bkflow/pipeline_plugins/test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/approve_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/approve_test/test_v1_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/test_v1_0_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/test_v1_0_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/http_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/http_test/test_v1_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/remote_plugin/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/remote_plugin/test_plugin.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/sleep_time_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/sleep_time_test/test_legacy.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/uniform_api_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v1_0_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v2_0_0.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/value_assign_test/__init__.py delete mode 100644 bkflow/pipeline_plugins/test/components/collections/value_assign_test/test_v1_0_0.py diff --git a/bkflow/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py b/bkflow/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py index baf69480c2..f256fe6e6a 100644 --- a/bkflow/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py +++ b/bkflow/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ TencentBlueKing is pleased to support the open source community by making 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. @@ -76,11 +77,13 @@ def plugin_execute(self, data, parent_data): data.set_outputs("ex_data", message) return False - plugin_context = { - key: parent_data.inputs[key] - for key in detail_result["data"]["context_inputs"]["properties"].keys() - if key in parent_data.inputs - } + plugin_context = dict( + [ + (key, parent_data.inputs[key]) + for key in detail_result["data"]["context_inputs"]["properties"].keys() + if key in parent_data.inputs + ] + ) ok, result_data = plugin_client.invoke( plugin_version, {"inputs": data.inputs, "context": plugin_context}, @@ -88,7 +91,7 @@ def plugin_execute(self, data, parent_data): ) if not ok: message = _("调用第三方插件invoke接口错误, 错误内容: {message}, trace_id: {trace_id}").format( - message=result_data["message"], trace_id=result_data.get("trace_id") + message=detail_result["message"], trace_id=result_data.get("trace_id") ) logger.error(message) data.set_outputs("ex_data", message) diff --git a/bkflow/pipeline_plugins/components/collections/value_assign/v1_0_0.py b/bkflow/pipeline_plugins/components/collections/value_assign/v1_0_0.py index fdcae282c5..96aca69694 100644 --- a/bkflow/pipeline_plugins/components/collections/value_assign/v1_0_0.py +++ b/bkflow/pipeline_plugins/components/collections/value_assign/v1_0_0.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ TencentBlueKing is pleased to support the open source community by making 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. @@ -61,7 +62,6 @@ def inputs_format(self): key="bk_assignment_list", type="object", schema=ObjectItemSchema( - property_schemas={}, description=_("赋值变量或常量与被赋值变量的映射列表"), ), ) diff --git a/bkflow/pipeline_plugins/test/__init__.py b/bkflow/pipeline_plugins/test/__init__.py deleted file mode 100644 index 732d2b8d52..0000000000 --- a/bkflow/pipeline_plugins/test/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" diff --git a/bkflow/pipeline_plugins/test/components/collections/__init__.py b/bkflow/pipeline_plugins/test/components/collections/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/approve_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/approve_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/approve_test/test_v1_0.py b/bkflow/pipeline_plugins/test/components/collections/approve_test/test_v1_0.py deleted file mode 100644 index c9b608c322..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/approve_test/test_v1_0.py +++ /dev/null @@ -1,175 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" - -from unittest.mock import MagicMock - -from django.test import TestCase -from pipeline.component_framework.test import ( - Call, - CallAssertion, - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, - ScheduleAssertion, -) - -from bkflow.pipeline_plugins.components.collections.approve.v1_0 import ApproveComponent - - -class BkApproveComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return ApproveComponent - - def cases(self): - return [ - CREATE_APPROVE_TICKET_FAIL_CASE, - CREATE_APPROVE_TICKET_SUCCESS_CASE, - REJECTED_BLOCK_SUCCESS_CASE, - ] - - -class MockClient: - def __init__(self, create_ticket=None): - self.create_ticket = MagicMock(return_value=create_ticket) - - -GET_CLIENT_BY_USER = "bkflow.pipeline_plugins.components.collections.approve.v1_0.BKItsmClient" -GET_NODE_CALLBACK_URL = "bkflow.pipeline_plugins.components.collections.approve.v1_0.get_node_callback_url" -BK_HANDLE_API_ERROR = "bkflow.pipeline_plugins.components.collections.approve.v1_0.handle_api_error" - -COMMON_PARENT = {"executor": "admin", "biz_cc_id": 2, "biz_supplier_account": 0} - -CREAT_TICKET_FAIL_RETURN = {"result": False, "message": "create ticket fail"} - -CREAT_TICKET_SUCCESS_RETURN = {"message": "success", "code": 0, "data": {"sn": "NO2019090519542603"}, "result": True} - -CALLBACK_URL_FAIL_RETURN = {"result": False, "message": "approve reject"} - -CALLBACK_URL_SUCCESS_RETURN = { - "sn": "REQ20200831000005", - "title": "this is a test", - "ticket_url": "https://xxx.xx.com", - "current_status": "FINISHED", - "updated_by": "admin,hongsong", - "update_at": "2020-08-31 20:57:22", - "approve_result": True, -} - -CALLBACK_URL_REJECT_RETURN = { - "sn": "REQ20200831000005", - "title": "this is a test", - "ticket_url": "https://xxx.xx.com", - "current_status": "FINISHED", - "updated_by": "admin,hongsong", - "update_at": "2020-08-31 20:57:22", - "approve_result": False, -} - -CREAT_TICKET_SUCCESS_CLIENT = MockClient(create_ticket=CREAT_TICKET_SUCCESS_RETURN) -CREAT_TICKET_FAIL_RETURN_CLIENT = MockClient(create_ticket=CREAT_TICKET_FAIL_RETURN) - -CREAT_TICKET_CALL = { - "creator": "admin", - "fields": [ - {"key": "title", "value": "this is a test"}, - {"key": "APPROVER", "value": "tester,tester1"}, - {"key": "APPROVAL_CONTENT", "value": "test content"}, - ], - "fast_approval": True, - "meta": {"callback_url": "callback_url"}, -} -INPUTS = { - "bk_verifier": "tester, tester1", - "bk_approve_title": "this is a test", - "bk_notify_title": "title", - "bk_approve_content": "test content", -} - -CREATE_APPROVE_TICKET_FAIL_CASE = ComponentTestCase( - name="create approve ticket fail case", - inputs=INPUTS, - parent_data=COMMON_PARENT, - execute_assertion=ExecuteAssertion(success=False, outputs={"ex_data": "create ticket fail"}), - execute_call_assertion=[ - CallAssertion( - func=CREAT_TICKET_FAIL_RETURN_CLIENT.create_ticket, - calls=[Call(**CREAT_TICKET_CALL)], - ) - ], - schedule_assertion=None, - patchers=[ - Patcher(target=GET_CLIENT_BY_USER, return_value=CREAT_TICKET_FAIL_RETURN_CLIENT), - Patcher(target=BK_HANDLE_API_ERROR, return_value="create ticket fail"), - Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), - ], -) - -CREATE_APPROVE_TICKET_SUCCESS_CASE = ComponentTestCase( - name="create approve ticket success case", - inputs=INPUTS, - parent_data=COMMON_PARENT, - execute_assertion=ExecuteAssertion(success=True, outputs={"sn": "NO2019090519542603"}), - execute_call_assertion=[ - CallAssertion( - func=CREAT_TICKET_SUCCESS_CLIENT.create_ticket, - calls=[Call(**CREAT_TICKET_CALL)], - ) - ], - schedule_assertion=ScheduleAssertion( - success=True, - outputs={"approve_result": "通过", "sn": "NO2019090519542603"}, - callback_data=CALLBACK_URL_SUCCESS_RETURN, - ), - patchers=[ - Patcher(target=GET_CLIENT_BY_USER, return_value=CREAT_TICKET_SUCCESS_CLIENT), - Patcher(target=BK_HANDLE_API_ERROR, return_value=""), - Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), - ], -) -BLOCKED_INPUTS = { - "bk_verifier": "tester, tester1", - "bk_approve_title": "this is a test", - "bk_notify_title": "title", - "bk_approve_content": "test content", - "rejected_block": False, -} - -REJECTED_BLOCK_SUCCESS_CASE = ComponentTestCase( - name="rejected_block success case", - inputs=BLOCKED_INPUTS, - parent_data=COMMON_PARENT, - execute_assertion=ExecuteAssertion(success=True, outputs={"sn": "NO2019090519542603"}), - execute_call_assertion=[ - CallAssertion( - func=CREAT_TICKET_SUCCESS_CLIENT.create_ticket, - calls=[Call(**CREAT_TICKET_CALL)], - ) - ], - schedule_assertion=ScheduleAssertion( - success=True, - outputs={"approve_result": "拒绝", "sn": "NO2019090519542603"}, - callback_data=CALLBACK_URL_REJECT_RETURN, - ), - patchers=[ - Patcher(target=GET_CLIENT_BY_USER, return_value=CREAT_TICKET_SUCCESS_CLIENT), - Patcher(target=BK_HANDLE_API_ERROR, return_value=""), - Patcher(target=GET_NODE_CALLBACK_URL, return_value="callback_url"), - ], -) diff --git a/bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/test_v1_0_0.py b/bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/test_v1_0_0.py deleted file mode 100644 index 8c61d0df9d..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/debug_plugin_test/test_v1_0_0.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" -import json - -from django.test import TestCase -from pipeline.component_framework.test import ( - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, -) - -from bkflow.pipeline_plugins.components.collections.debug_plugin.v1_0_0 import ( - DebugPluginComponent, -) - - -class DebugPluginComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return DebugPluginComponent - - def cases(self): - return [DEBUG_PLUGIN_EXECUTE] - - -INPUTS = {"string_input": "string", "int_input": 1, "boolean_input": True, "object_input": json.dumps({"key": "value"})} - -OUTPUT = {"string_output": "string", "int_output": 1, "boolean_output": True, "object_output": {"key": "value"}} - -DEBUG_PLUGIN_EXECUTE = ComponentTestCase( - name="debug plugin execute", - inputs=INPUTS, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs=OUTPUT), - schedule_assertion=None, -) diff --git a/bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/test_v1_0_0.py b/bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/test_v1_0_0.py deleted file mode 100644 index 5d776286fa..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/dmn_plugin_test/test_v1_0_0.py +++ /dev/null @@ -1,125 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" - -from unittest.mock import MagicMock - -from django.test import TestCase -from pipeline.component_framework.test import ( - Call, - CallAssertion, - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, -) - -from bkflow.pipeline_plugins.components.collections.dmn_plugin.v1_0_0 import ( - DmnPluginComponent, -) - -TEST_SPACE_ID = "some_space_id" -TEST_TABLE_ID = "some_table_id" -TEST_FACTS = { - "input_param_1": {"value": "some_value", "variable": False}, - "input_param_2": {"value": "another_value", "variable": True}, -} - -SUCCESS_RESPONSE = { - "result": True, - "data": { - "name": "some_decision_table", - "data": { - "inputs": [{"id": "input_param_1", "name": "input_param_1", "type": "string"}], - "outputs": [{"id": "output_param_1", "name": "output_param_1", "type": "string"}], - "records": [ - { - "inputs": { - "type": "common", - "conditions": [ - {"compare": "equals", "right": {"obj": {"type": "string", "value": "some_value"}}} - ], - }, - "outputs": {"output_param_1": "some_output_value"}, - } - ], - }, - }, -} - -FAIL_RESPONSE = {"result": False, "message": "some_error_message"} - - -class MockClient: - def __init__(self, get_decision_table=None): - self.get_decision_table = MagicMock(return_value=get_decision_table) - - -MOCK_SUCCESS_CLIENT = MockClient(get_decision_table=SUCCESS_RESPONSE) -MOCK_FAIL_CLIENT = MockClient(get_decision_table=FAIL_RESPONSE) - - -class DmnPluginComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return DmnPluginComponent - - def cases(self): - return [DMN_PLUGIN_SUCCESS_CASE, DMN_PLUGIN_FAIL_CASE] - - -DMN_PLUGIN_SUCCESS_CASE = ComponentTestCase( - name="dmn_plugin_success_case", - inputs={"facts": TEST_FACTS, "table_id": TEST_TABLE_ID}, - parent_data={"task_space_id": TEST_SPACE_ID}, - execute_assertion=ExecuteAssertion(success=True, outputs={"output_param_1": "some_output_value"}), - execute_call_assertion=[ - CallAssertion( - func=MOCK_SUCCESS_CLIENT.get_decision_table, - calls=[Call(decision_table_id=TEST_TABLE_ID, data={"space_id": TEST_SPACE_ID})], - ) - ], - schedule_assertion=None, - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.dmn_plugin.v1_0_0.InterfaceModuleClient", - return_value=MOCK_SUCCESS_CLIENT, - ) - ], -) - -DMN_PLUGIN_FAIL_CASE = ComponentTestCase( - name="dmn_plugin_fail_case", - inputs={"facts": TEST_FACTS, "table_id": TEST_TABLE_ID}, - parent_data={"task_space_id": TEST_SPACE_ID}, - execute_assertion=ExecuteAssertion( - success=False, outputs={"ex_data": "[get decision table] error: some_error_message"} - ), - execute_call_assertion=[ - CallAssertion( - func=MOCK_FAIL_CLIENT.get_decision_table, - calls=[Call(decision_table_id=TEST_TABLE_ID, data={"space_id": TEST_SPACE_ID})], - ) - ], - schedule_assertion=None, - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.dmn_plugin.v1_0_0.InterfaceModuleClient", - return_value=MOCK_FAIL_CLIENT, - ) - ], -) diff --git a/bkflow/pipeline_plugins/test/components/collections/http_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/http_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/http_test/test_v1_0.py b/bkflow/pipeline_plugins/test/components/collections/http_test/test_v1_0.py deleted file mode 100644 index 95de189fac..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/http_test/test_v1_0.py +++ /dev/null @@ -1,441 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" - - -from unittest.mock import MagicMock - -from django.conf import settings -from django.test import TestCase -from pipeline.component_framework.test import ( - Call, - CallAssertion, - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, - ScheduleAssertion, -) - -from bkflow.pipeline_plugins.components.collections.http.v1_0 import HttpComponent - - -class HttpComponentTest(TestCase, ComponentTestMixin): - def setUp(self): - settings.ENABLE_HTTP_PLUGIN_DOMAINS_CHECK = False - - def cases(self): - return [ - HTTP_CALL_REQUEST_ERR_CASE, - HTTP_CALL_RESP_NOT_JSON_CASE, - HTTP_CALL_RESP_STATUS_CODE_ERR_CASE, - HTTP_CALL_EXP_TEST_ERR_CASE, - HTTP_CALL_NO_HEADER_CASE, - HTTP_CALL_WITH_HEADER_CASE, - HTTP_CALL_EXP_FAIL_CASE, - HTTP_CALL_EXP_SUCCESS_CASE, - ] - - def component_cls(self): - return HttpComponent - - -HTTP_REQUEST = "bkflow.pipeline_plugins.components.collections.http.v1_0.request" -HTTP_BOOLRULE = "bkflow.pipeline_plugins.components.collections.http.v1_0.BoolRule" - - -HTTP_CALL_REQUEST_ERR_CASE = ComponentTestCase( - name="http call request error case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token", - "bk_http_timeout": 0, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion(success=False, outputs={"ex_data": "请求异常,详细信息: exc_token1"}), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - timeout=60, - headers={"Content-type": "application/json"}, - ) - ], - ) - ], - patchers=[Patcher(target=HTTP_REQUEST, side_effect=Exception("exc_token1"))], -) - -# ------------------------------------------------ - -NOT_JSON_RESPONSE = MagicMock() -NOT_JSON_RESPONSE.json = MagicMock(side_effect=Exception("exc_token2")) -NOT_JSON_RESPONSE.status_code = 200 - -HTTP_CALL_RESP_NOT_JSON_CASE = ComponentTestCase( - name="http call response is not json case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token", - "bk_http_timeout": 0, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=False, outputs={"ex_data": "请求响应数据格式非 JSON", "status_code": NOT_JSON_RESPONSE.status_code} - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - timeout=60, - headers={"Content-type": "application/json"}, - ) - ], - ) - ], - patchers=[Patcher(target=HTTP_REQUEST, return_value=NOT_JSON_RESPONSE)], -) - -# ------------------------------------------------ - -STAUS_500_RESPONSE = MagicMock() -STAUS_500_RESPONSE.json = MagicMock(return_value="json_token1") -STAUS_500_RESPONSE.status_code = 500 - -HTTP_CALL_RESP_STATUS_CODE_ERR_CASE = ComponentTestCase( - name="http call response status 500 case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token", - "bk_http_timeout": 100, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=False, - outputs={ - "ex_data": "请求失败,状态码: {},响应: {}".format(STAUS_500_RESPONSE.status_code, STAUS_500_RESPONSE.json()), - "data": STAUS_500_RESPONSE.json(), - "status_code": STAUS_500_RESPONSE.status_code, - }, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - timeout=60, - headers={"Content-type": "application/json"}, - ) - ], - ) - ], - patchers=[Patcher(target=HTTP_REQUEST, return_value=STAUS_500_RESPONSE)], -) - -# ------------------------------------------------ - -TEST_ERR_BOOLRULE = MagicMock() -TEST_ERR_BOOLRULE.test = MagicMock(side_effect=Exception("exc_token3")) - -EXP_TEST_ERR_RESPONSE = MagicMock() -EXP_TEST_ERR_RESPONSE.json = MagicMock(return_value="json_token2") -EXP_TEST_ERR_RESPONSE.status_code = 200 - -HTTP_CALL_EXP_TEST_ERR_CASE = ComponentTestCase( - name="http call bool rule test err case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token", - "bk_http_timeout": 5, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=False, - outputs={ - "data": EXP_TEST_ERR_RESPONSE.json(), - "status_code": EXP_TEST_ERR_RESPONSE.status_code, - "ex_data": "请求成功条件判定出错: exc_token3", - }, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - timeout=5, - headers={"Content-type": "application/json"}, - ) - ], - ), - CallAssertion(func=TEST_ERR_BOOLRULE.test, calls=[Call(context={"resp": EXP_TEST_ERR_RESPONSE.json()})]), - ], - patchers=[ - Patcher(target=HTTP_REQUEST, return_value=EXP_TEST_ERR_RESPONSE), - Patcher(target=HTTP_BOOLRULE, return_value=TEST_ERR_BOOLRULE), - ], -) - -# ------------------------------------------------ - -HTTP_CALL_NO_HEADER_RESPONSE = MagicMock() -HTTP_CALL_NO_HEADER_RESPONSE.json = MagicMock(return_value="json_token3") -HTTP_CALL_NO_HEADER_RESPONSE.status_code = 200 - -HTTP_CALL_NOT_HEADER_BOOLRULE = MagicMock() - -HTTP_CALL_NO_HEADER_CASE = ComponentTestCase( - name="http call no header case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "", - "bk_http_timeout": -1, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=True, - schedule_finished=True, - outputs={"data": HTTP_CALL_NO_HEADER_RESPONSE.json(), "status_code": HTTP_CALL_NO_HEADER_RESPONSE.status_code}, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - headers={"Content-type": "application/json"}, - timeout=1, - ) - ], - ), - CallAssertion(func=HTTP_CALL_NOT_HEADER_BOOLRULE.test, calls=[]), - ], - patchers=[ - Patcher(target=HTTP_REQUEST, return_value=HTTP_CALL_NO_HEADER_RESPONSE), - Patcher(target=HTTP_BOOLRULE, return_value=HTTP_CALL_NOT_HEADER_BOOLRULE), - ], -) - -# ------------------------------------------------ - -HTTP_CALL_WITH_HEADER_RESPONSE = MagicMock() -HTTP_CALL_WITH_HEADER_RESPONSE.json = MagicMock(return_value="json_token3") -HTTP_CALL_WITH_HEADER_RESPONSE.status_code = 200 - -HTTP_CALL_WITH_HEADER_BOOLRULE = MagicMock() - -HTTP_CALL_WITH_HEADER_CASE = ComponentTestCase( - name="http call with header case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [{"name": "name1", "value": "value1"}, {"name": "name2", "value": "value2"}], - "bk_http_success_exp": "", - "bk_http_timeout": 1, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=True, - schedule_finished=True, - outputs={ - "data": HTTP_CALL_WITH_HEADER_RESPONSE.json(), - "status_code": HTTP_CALL_WITH_HEADER_RESPONSE.status_code, - }, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - headers={"name2": "value2", "Content-type": "application/json", "name1": "value1"}, - timeout=1, - ) - ], - ), - CallAssertion(func=HTTP_CALL_WITH_HEADER_BOOLRULE.test, calls=[]), - ], - patchers=[ - Patcher(target=HTTP_REQUEST, return_value=HTTP_CALL_WITH_HEADER_RESPONSE), - Patcher(target=HTTP_BOOLRULE, return_value=HTTP_CALL_WITH_HEADER_BOOLRULE), - ], -) - -# ------------------------------------------------ - -HTTP_CALL_EXP_FAIL_RESPONSE = MagicMock() -HTTP_CALL_EXP_FAIL_RESPONSE.json = MagicMock(return_value="json_token4") -HTTP_CALL_EXP_FAIL_RESPONSE.status_code = 200 - -HTTP_CALL_EXP_FAIL_BOOLRULE = MagicMock() -HTTP_CALL_EXP_FAIL_BOOLRULE.test = MagicMock(return_value=False) - -HTTP_CALL_EXP_FAIL_CASE = ComponentTestCase( - name="http call expression fail case", - inputs={ - "bk_http_request_method": "GET", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token1", - "bk_http_timeout": 0, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=False, - outputs={ - "data": HTTP_CALL_EXP_FAIL_RESPONSE.json(), - "status_code": HTTP_CALL_EXP_FAIL_RESPONSE.status_code, - "ex_data": "请求成功判定失败", - }, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, calls=[Call(method="GET", url="url_token", verify=False, timeout=60, headers={})] - ), - CallAssertion(func=HTTP_CALL_EXP_FAIL_BOOLRULE.test, calls=[Call(context={"resp": "json_token4"})]), - ], - patchers=[ - Patcher(target=HTTP_REQUEST, return_value=HTTP_CALL_EXP_FAIL_RESPONSE), - Patcher(target=HTTP_BOOLRULE, return_value=HTTP_CALL_EXP_FAIL_BOOLRULE), - ], -) - -# ------------------------------------------------ - -HTTP_CALL_EXP_SUCCESS_RESPONSE = MagicMock() -HTTP_CALL_EXP_SUCCESS_RESPONSE.json = MagicMock(return_value="json_token5") -HTTP_CALL_EXP_SUCCESS_RESPONSE.status_code = 200 - -HTTP_CALL_EXP_SUCCESS_BOOLRULE = MagicMock() -HTTP_CALL_EXP_SUCCESS_BOOLRULE.test = MagicMock(return_value=True) - -HTTP_CALL_EXP_SUCCESS_CASE = ComponentTestCase( - name="http call expression success case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token2", - "bk_http_timeout": 0, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion( - success=True, - schedule_finished=True, - outputs={ - "data": HTTP_CALL_EXP_SUCCESS_RESPONSE.json(), - "status_code": HTTP_CALL_EXP_SUCCESS_RESPONSE.status_code, - }, - ), - schedule_call_assertion=[ - CallAssertion( - func=HTTP_REQUEST, - calls=[ - Call( - method="method_token", - url="url_token", - verify=False, - data=b"body_token", - timeout=60, - headers={"Content-type": "application/json"}, - ) - ], - ), - CallAssertion(func=HTTP_CALL_EXP_SUCCESS_BOOLRULE.test, calls=[Call(context={"resp": "json_token5"})]), - ], - patchers=[ - Patcher(target=HTTP_REQUEST, return_value=HTTP_CALL_EXP_SUCCESS_RESPONSE), - Patcher(target=HTTP_BOOLRULE, return_value=HTTP_CALL_EXP_SUCCESS_BOOLRULE), - ], -) - - -class HttpComponentValidateTestCase(TestCase, ComponentTestMixin): - def setUp(self): - settings.ENABLE_HTTP_PLUGIN_DOMAINS_CHECK = True - - def cases(self): - return [HTTP_CALL_REQUEST_VALIDATE_CASE] - - def component_cls(self): - return HttpComponent - - -HTTP_CALL_REQUEST_VALIDATE_CASE = ComponentTestCase( - name="http call request error case", - inputs={ - "bk_http_request_method": "method_token", - "bk_http_request_url": "url_token", - "bk_http_request_body": "body_token", - "bk_http_request_header": [], - "bk_http_success_exp": "exp_token", - "bk_http_timeout": 0, - }, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=ScheduleAssertion(success=False, outputs={"ex_data": "仅允许访问域名(.)下的URL"}), -) diff --git a/bkflow/pipeline_plugins/test/components/collections/remote_plugin/__init__.py b/bkflow/pipeline_plugins/test/components/collections/remote_plugin/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/remote_plugin/test_plugin.py b/bkflow/pipeline_plugins/test/components/collections/remote_plugin/test_plugin.py deleted file mode 100644 index cb009b2785..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/remote_plugin/test_plugin.py +++ /dev/null @@ -1,157 +0,0 @@ -""" -Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community -Edition) available. -Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" - -from unittest.mock import MagicMock - -from django.test import TestCase -from pipeline.component_framework.test import ( - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, - ScheduleAssertion, -) - -from bkflow.pipeline_plugins.components.collections.remote_plugin.v1_0_0 import ( - RemotePluginComponent, - State, -) - - -class RemotePluginComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - # return the component class which should be tested - return RemotePluginComponent - - def cases(self): - # return your component test cases here - return [ - EXECUTE_SUCCESS_CASE, - EXECUTE_AND_SCHEDULE_SUCCESS_CASE, - EXECUTE_FAIL_CASE, - INVOKE_API_FAIL_CASE, - SCHEDULE_FAIL_CASE, - ] - - -class MockPluginClient: - def __init__(self, invoke_result=None, get_schedule_result=None, get_detail_result=None): - self.invoke = MagicMock(return_value=invoke_result) - self.get_schedule = MagicMock(return_value=get_schedule_result) - self.get_detail = MagicMock(return_value=get_detail_result) - - -# mock path -PLUGIN_SERVICE_API_CLIENT = "bkflow.pipeline_plugins.components.collections.remote_plugin.v1_0_0.PluginServiceApiClient" - -# parent_data -PARENT_DATA = {"executor": "executor", "biz_cc_id": 1} - -# INPUTS -BASE_INPUTS = {"plugin_code": "code", "plugin_version": "version"} - -# OUTPUTS -BASE_OUTPUTS = {"output": "output"} -INVOKE_FAIL_EX_DATA_OUTPUTS = {"ex_data": "调用第三方插件invoke接口错误, 错误内容: ex_data, trace_id: trace_id"} -STATE_FAIL_EX_DATA_OUTPUTS = {"ex_data": "state fail"} -SCHEDULE_FAIL_EX_DATA_OUTPUTS = {"ex_data": "请通过第三方节点日志查看任务失败原因"} -TRACE_ID_OUTPUTS = {"trace_id": "trace_id"} - -# mock clients -ONLY_EXECUTE_AND_SUCCESS_CLIENT = MockPluginClient( - invoke_result=(True, {**TRACE_ID_OUTPUTS, "state": State.SUCCESS, "outputs": BASE_OUTPUTS}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -EXECUTE_AND_SCHEDULE_SUCCESS_CLIENT = MockPluginClient( - invoke_result=(True, {**TRACE_ID_OUTPUTS, "state": State.POLL, "outputs": {}}), - get_schedule_result=(True, {"state": State.SUCCESS, "outputs": BASE_OUTPUTS}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -EXECUTE_AND_SCHEDULE_SUCCESS_CALLBACK_CLIENT = MockPluginClient( - invoke_result=(True, {**TRACE_ID_OUTPUTS, "state": State.CALLBACK, "outputs": {}}), - get_schedule_result=(True, {"state": State.SUCCESS, "outputs": BASE_OUTPUTS}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -INVOKE_API_FAIL_CLIENT = MockPluginClient( - invoke_result=(False, {**TRACE_ID_OUTPUTS, "message": "ex_data"}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -EXECUTE_FAIL_CLIENT = MockPluginClient( - invoke_result=(True, {**TRACE_ID_OUTPUTS, "state": State.FAIL, "err": "state fail"}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -SCHEDULE_FAIL_CLIENT = MockPluginClient( - invoke_result=(True, {**TRACE_ID_OUTPUTS, "state": State.POLL, "outputs": {}}), - get_schedule_result=(True, {"state": State.FAIL, "outputs": BASE_OUTPUTS}), - get_detail_result={"result": True, "data": {"context_inputs": {"properties": {}}}}, -) - -# only execute success -EXECUTE_SUCCESS_CASE = ComponentTestCase( - name="Only need execute and success case", - inputs=BASE_INPUTS, - parent_data=PARENT_DATA, - execute_assertion=ExecuteAssertion(success=True, outputs={**TRACE_ID_OUTPUTS, **BASE_OUTPUTS}), - schedule_assertion=None, - patchers=[Patcher(target=PLUGIN_SERVICE_API_CLIENT, return_value=ONLY_EXECUTE_AND_SUCCESS_CLIENT)], -) - -# both execute and schedule success -EXECUTE_AND_SCHEDULE_SUCCESS_CASE = ComponentTestCase( - name="Both execute and schedule success case", - inputs=BASE_INPUTS, - parent_data=PARENT_DATA, - execute_assertion=ExecuteAssertion(success=True, outputs={**TRACE_ID_OUTPUTS}), - schedule_assertion=ScheduleAssertion( - success=True, outputs={**TRACE_ID_OUTPUTS, **BASE_OUTPUTS}, callback_data={}, schedule_finished=True - ), - patchers=[Patcher(target=PLUGIN_SERVICE_API_CLIENT, return_value=EXECUTE_AND_SCHEDULE_SUCCESS_CLIENT)], -) - -# execute fail because invoke api fail -INVOKE_API_FAIL_CASE = ComponentTestCase( - name="execute fail because invoke api fail", - inputs=BASE_INPUTS, - parent_data=PARENT_DATA, - execute_assertion=ExecuteAssertion(success=False, outputs={**INVOKE_FAIL_EX_DATA_OUTPUTS}), - schedule_assertion=None, - patchers=[Patcher(target=PLUGIN_SERVICE_API_CLIENT, return_value=INVOKE_API_FAIL_CLIENT)], -) - -# execute fail because state fail -EXECUTE_FAIL_CASE = ComponentTestCase( - name="execute fail because state fail", - inputs=BASE_INPUTS, - parent_data=PARENT_DATA, - execute_assertion=ExecuteAssertion(success=False, outputs={**TRACE_ID_OUTPUTS, **STATE_FAIL_EX_DATA_OUTPUTS}), - schedule_assertion=None, - patchers=[Patcher(target=PLUGIN_SERVICE_API_CLIENT, return_value=EXECUTE_FAIL_CLIENT)], -) - -# schedule fail -SCHEDULE_FAIL_CASE = ComponentTestCase( - name="schedule fail", - inputs=BASE_INPUTS, - parent_data=PARENT_DATA, - execute_assertion=ExecuteAssertion(success=True, outputs={**TRACE_ID_OUTPUTS}), - schedule_assertion=ScheduleAssertion( - success=False, - outputs={**TRACE_ID_OUTPUTS, **SCHEDULE_FAIL_EX_DATA_OUTPUTS, **BASE_OUTPUTS}, - callback_data={}, - ), - patchers=[Patcher(target=PLUGIN_SERVICE_API_CLIENT, return_value=SCHEDULE_FAIL_CLIENT)], -) diff --git a/bkflow/pipeline_plugins/test/components/collections/sleep_time_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/sleep_time_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/sleep_time_test/test_legacy.py b/bkflow/pipeline_plugins/test/components/collections/sleep_time_test/test_legacy.py deleted file mode 100644 index bef17e3dab..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/sleep_time_test/test_legacy.py +++ /dev/null @@ -1,90 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" -import datetime -import time - -from django.conf import settings -from django.test import TestCase -from django.utils import timezone -from pipeline.component_framework.test import ( - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - ScheduleAssertion, -) - -from bkflow.pipeline_plugins.components.collections.sleep_time.legacy import ( - SleepTimerComponent, -) - - -class SleepTimerComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return SleepTimerComponent - - def cases(self): - return [INVALID_SECONDS_TEST_CASE, VALID_DATETIME_TEST_CASE] - - -INVALID_SECONDS_INPUT = {"bk_timing": time.time() + 60, "force_check": True} -VALID_DATETIME_INPUT = { - "bk_timing": (datetime.datetime.now() + datetime.timedelta(seconds=60)).strftime("%Y-%m-%d %H:%M:%S"), - "force_check": True, -} -VALID_SECONDS_INPUT = {"bk_timing": 10, "force_check": True} -BUSINESS_TIMEZONE = timezone.pytz.timezone(settings.TIME_ZONE) - -INVALID_SECONDS_TEST_CASE = ComponentTestCase( - name="invalid seconds input test case", - inputs=INVALID_SECONDS_INPUT, - parent_data={}, - execute_assertion=ExecuteAssertion( - success=False, - outputs={ - "business_tz": BUSINESS_TIMEZONE, - "ex_data": "输入参数%s不符合【秒(s) 或 时间(%%Y-%%m-%%d %%H:%%M:%%S)】格式" % INVALID_SECONDS_INPUT["bk_timing"], - }, - ), - schedule_assertion=None, -) - -VALID_DATETIME_TEST_CASE = ComponentTestCase( - name="valid datetime input test case", - inputs=VALID_DATETIME_INPUT, - parent_data={}, - execute_assertion=ExecuteAssertion( - success=True, - outputs={ - "business_tz": BUSINESS_TIMEZONE, - "timing_time": BUSINESS_TIMEZONE.localize( - datetime.datetime.strptime(VALID_DATETIME_INPUT["bk_timing"], "%Y-%m-%d %H:%M:%S") - ), - }, - ), - schedule_assertion=ScheduleAssertion( - success=True, - outputs={ - "business_tz": BUSINESS_TIMEZONE, - "timing_time": BUSINESS_TIMEZONE.localize( - datetime.datetime.strptime(VALID_DATETIME_INPUT["bk_timing"], "%Y-%m-%d %H:%M:%S") - ), - }, - callback_data={}, - ), -) diff --git a/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v1_0_0.py b/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v1_0_0.py deleted file mode 100644 index 153e7054b9..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v1_0_0.py +++ /dev/null @@ -1,127 +0,0 @@ -""" -Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community -Edition) available. -Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" - -from unittest.mock import MagicMock - -from django.test import TestCase -from pipeline.component_framework.test import ( - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, -) - -from bkflow.pipeline_plugins.components.collections.uniform_api.v1_0_0 import ( - UniformAPIComponent, -) - - -class UniformAPIComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return UniformAPIComponent - - def cases(self): - return [SUCCESS_TEST_CASE, FAILURE_TEST_CASE] - - -class MockRequestResult: - def __init__(self, status_code, json_resp, message, result): - self.resp = MagicMock(status_code=status_code) - self.json_resp = json_resp - self.message = message - self.result = result - - -TEST_API_CONFIG = { - "url": "https://example.com/api", - "method": "POST", - "params": [{"key": "param1", "value": "value1"}, {"key": "param2", "value": "value2"}], - "timeout": 30, -} - -TEST_PARENT_DATA = { - "operator": "admin", - "task_space_id": "space123", - "task_scope_type": "project", - "task_scope_value": "project123", - "task_id": "task123", - "task_name": "test_task", -} - -SUCCESS_SPACE_INFO = { - "result": True, - "message": "success", - "data": { - "configs": { - "uniform_api": {"enable_api_parameter_conversion": True}, - "credential": {"bk_app_code": "mock_app_code", "bk_app_secret": "mock_app_secret"}, - } - }, -} -SUCCESS_API_HEADERS = { - "X-Bkapi-Authorization": "mock_token", - "X-Bkapi-App-Code": "mock_app_code", - "X-Bkapi-App-Secret": "mock_app_secret", - "X-Bkapi-User": "mock_operator", -} -SUCCESS_API_RESPONSE = MockRequestResult( - status_code=200, json_resp={"result": "success", "data": {"space_id": 1}}, message="success", result=True -) - - -class MockAPIClient: - def __init__(self, get_space_infos=None, gen_default_apigw_header=None, request=None): - self.get_space_infos = MagicMock(return_value=get_space_infos) - self.gen_default_apigw_header = MagicMock(return_value=gen_default_apigw_header) - self.request = MagicMock(return_value=request) - - -SUCCESS_CLIENT = MockAPIClient( - get_space_infos=SUCCESS_SPACE_INFO, gen_default_apigw_header=SUCCESS_API_HEADERS, request=SUCCESS_API_RESPONSE -) -FAILURE_CLIENT = MockAPIClient(get_space_infos={"result": False, "message": "get space infos failed"}) - -SUCCESS_TEST_CASE = ComponentTestCase( - name="uniform_api_success_test", - inputs={"api_config": TEST_API_CONFIG}, - parent_data={**TEST_PARENT_DATA}, - execute_assertion=ExecuteAssertion( - success=True, outputs={"status_code": 200, "data": {"result": "success", "data": {"space_id": 1}}} - ), - schedule_assertion=None, - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v1_0_0.InterfaceModuleClient", - return_value=SUCCESS_CLIENT, - ), - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v1_0_0.UniformAPIClient", - return_value=SUCCESS_CLIENT, - ), - ], -) - -FAILURE_TEST_CASE = ComponentTestCase( - name="uniform_api_failure_test", - inputs={"api_config": TEST_API_CONFIG}, - parent_data={**TEST_PARENT_DATA}, - execute_assertion=ExecuteAssertion( - success=False, outputs={"ex_data": "[uniform_api error] get apigw credential failed: get space infos failed"} - ), - schedule_assertion=None, - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v1_0_0.InterfaceModuleClient", - return_value=FAILURE_CLIENT, - ) - ], -) diff --git a/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v2_0_0.py b/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v2_0_0.py deleted file mode 100644 index e6bc90c573..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/uniform_api_test/test_v2_0_0.py +++ /dev/null @@ -1,152 +0,0 @@ -""" -Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community -Edition) available. -Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. -""" -from unittest.mock import MagicMock - -from django.test import TestCase -from pipeline.component_framework.test import ( - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, - ScheduleAssertion, -) - -from bkflow.pipeline_plugins.components.collections.uniform_api.v2_0_0 import ( - UniformAPIComponent, -) - - -class UniformAPIComponentTest(TestCase, ComponentTestMixin): - def component_cls(self): - return UniformAPIComponent - - def cases(self): - return [API_TRIGGER_SUCCESS_CASE, API_CALLBACK_SUCCESS_CASE] - - -API_INPUT_DATA = { - "uniform_api_plugin_callback": { - "success_tag": {"key": "result", "value": "success"}, - "fail_tag": {"key": "result", "value": "fail"}, - }, - "uniform_api_plugin_url": "http://example.com", - "uniform_api_plugin_polling": True, - "uniform_api_plugin_method": "GET", - "response_data_path": None, -} - -API_CALLBACK_INPUT_DATA = {**API_INPUT_DATA, "need_callback": True} - -TEST_PARENT_DATA = { - "operator": "admin", - "task_space_id": 1, - "task_scope_type": "project", - "task_scope_value": "project-1", - "task_id": 1, - "task_name": "test_task", -} - - -class MockAPIResponse: - def __init__(self, status_code, json_resp, message, result): - self.resp = MagicMock(status_code=status_code) - self.json_resp = json_resp - self.message = message - self.result = result - - -SUCCESS_SPACE_CONFIG = { - "result": True, - "message": "success", - "data": { - "configs": { - "uniform_api": { - "api": { - "default": { - "meta_apis": "https://example.com/meta_apis", - "api_categories": "https://example.com/api_categories", - "display_name": "Default API", - } - }, - "enable_api_parameter_conversion": True, - }, - "credential": {"bk_app_code": "mock_app_code", "bk_app_secret": "mock_app_secret"}, - } - }, -} -SUCCESS_API_HEADER = { - "X-Bkapi-Authorization": "mock_token", - "X-Bkapi-App-Code": "mock_app_code", - "X-Bkapi-App-Secret": "mock_app_secret", - "X-Bkapi-User": "mock_operator", -} -SUCCESS_API_RESPONSE_DATA = MockAPIResponse( - status_code=200, json_resp={"result": "success", "data": {"space_id": 1}}, message="success", result=True -) - - -class MockUniformAPIClient: - def __init__(self, get_space_infos=None, gen_default_apigw_header=None, request=None): - self.get_space_infos = MagicMock(return_value=get_space_infos) - self.gen_default_apigw_header = MagicMock(return_value=gen_default_apigw_header) - self.request = MagicMock(return_value=request) - - -SUCCESS_API_CLIENT = MockUniformAPIClient( - get_space_infos=SUCCESS_SPACE_CONFIG, gen_default_apigw_header=SUCCESS_API_HEADER, request=SUCCESS_API_RESPONSE_DATA -) - - -API_TRIGGER_SUCCESS_CASE = ComponentTestCase( - name="api_trigger_success_case", - inputs={**API_INPUT_DATA}, - parent_data={**TEST_PARENT_DATA}, - execute_assertion=ExecuteAssertion(outputs={"need_callback": True, "status_code": 200}, success=True), - schedule_assertion=ScheduleAssertion( - outputs={"need_callback": True, "status_code": 200}, success=True, callback_data={"result": "success"} - ), - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v2_0_0.InterfaceModuleClient", - return_value=SUCCESS_API_CLIENT, - ), - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v2_0_0.UniformAPIClient", - return_value=SUCCESS_API_CLIENT, - ), - ], -) - -API_CALLBACK_SUCCESS_CASE = ComponentTestCase( - name="api_callback_success_case", - inputs={**API_CALLBACK_INPUT_DATA}, - parent_data={**TEST_PARENT_DATA}, - execute_assertion=ExecuteAssertion( - success=True, - outputs={"need_callback": True, "status_code": 200}, - ), - schedule_assertion=ScheduleAssertion( - success=True, - callback_data={"result": "success"}, - outputs={"need_callback": True, "status_code": 200}, - ), - patchers=[ - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v2_0_0.InterfaceModuleClient", - return_value=SUCCESS_API_CLIENT, - ), - Patcher( - target="bkflow.pipeline_plugins.components.collections.uniform_api.v2_0_0.UniformAPIClient", - return_value=SUCCESS_API_CLIENT, - ), - ], -) diff --git a/bkflow/pipeline_plugins/test/components/collections/value_assign_test/__init__.py b/bkflow/pipeline_plugins/test/components/collections/value_assign_test/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bkflow/pipeline_plugins/test/components/collections/value_assign_test/test_v1_0_0.py b/bkflow/pipeline_plugins/test/components/collections/value_assign_test/test_v1_0_0.py deleted file mode 100644 index 528d0ed5fe..0000000000 --- a/bkflow/pipeline_plugins/test/components/collections/value_assign_test/test_v1_0_0.py +++ /dev/null @@ -1,100 +0,0 @@ -""" -TencentBlueKing is pleased to support the open source community by making -蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. -Copyright (C) 2024 THL A29 Limited, -a Tencent company. All rights reserved. -Licensed under the MIT License (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://opensource.org/licenses/MIT -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on -an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -either express or implied. See the License for the -specific language governing permissions and limitations under the License. - -We undertake not to change the open source license (MIT license) applicable - -to the current version of the project delivered to anyone in the future. -""" - -from unittest.mock import MagicMock - -from bamboo_engine.eri import ContextValue, ContextValueType -from django.test import TestCase -from pipeline.component_framework.test import ( - Call, - CallAssertion, - ComponentTestCase, - ComponentTestMixin, - ExecuteAssertion, - Patcher, -) - -from bkflow.pipeline_plugins.components.collections.value_assign.v1_0_0 import ( - ValueAssignComponent, - ValueAssignService, -) - - -class ValueAssignComponentTest(TestCase, ComponentTestMixin): - def setUp(self): - ValueAssignService.top_pipeline_id = "top_pipeline_id" - - def component_cls(self): - return ValueAssignComponent - - def cases(self): - return [SUCCESS_TEST_CASE, FAILURE_TEST_CASE] - - -ASSIGNMENT_DATA = [ - {"key": "var1", "value": "hello", "value_type": "String"}, -] - -SUCCESS_CONTEXT_VALUES = [ContextValue(key="${var1}", type=ContextValueType.PLAIN, value="123", code=None)] -FAILURE_CONTEXT_VALUES = [ContextValue(key="${var1}", type=ContextValueType.PLAIN, value=123, code=None)] - - -BAMBOO_RUNTIME_CLASS = "bkflow.pipeline_plugins.components.collections.value_assign.v1_0_0.BambooDjangoRuntime" - - -class MockContextClient: - def __init__(self, get_context_values): - self.get_context_values = MagicMock(return_value=get_context_values) - self.update_context_values = MagicMock(return_value=True) - - -SUCCESS_CLIENT = MockContextClient(get_context_values=SUCCESS_CONTEXT_VALUES) -FAILURE_CLIENT = MockContextClient(get_context_values=FAILURE_CONTEXT_VALUES) - - -SUCCESS_TEST_CASE = ComponentTestCase( - name="value_assign_success_test", - inputs={"bk_assignment_list": ASSIGNMENT_DATA}, - parent_data={}, - execute_assertion=ExecuteAssertion(success=True, outputs={}), - schedule_assertion=None, - execute_call_assertion=[ - CallAssertion( - func=SUCCESS_CLIENT.get_context_values, calls=[Call(pipeline_id="top_pipeline_id", keys={"${var1}"})] - ) - ], - patchers=[Patcher(target=BAMBOO_RUNTIME_CLASS, return_value=SUCCESS_CLIENT)], -) - -FAILURE_TEST_CASE = ComponentTestCase( - name="value_assign_failure_test", - inputs={"bk_assignment_list": ASSIGNMENT_DATA}, - parent_data={}, - execute_assertion=ExecuteAssertion( - success=False, outputs={"ex_data": "expected type String not match target variable type "} - ), - schedule_assertion=None, - execute_call_assertion=[ - CallAssertion( - func=FAILURE_CLIENT.get_context_values, - calls=[Call(pipeline_id="top_pipeline_id", keys={"${var1}"})], - ) - ], - patchers=[Patcher(target=BAMBOO_RUNTIME_CLASS, return_value=FAILURE_CLIENT)], -) diff --git a/config/__init__.py b/config/__init__.py index 67ebbea194..64f3448b4b 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ TencentBlueKing is pleased to support the open source community by making 蓝鲸流程引擎服务 (BlueKing Flow Engine Service) available. @@ -18,6 +19,8 @@ """ +from __future__ import absolute_import + import os # This will make sure the app is always imported when @@ -52,7 +55,7 @@ def get_env_or_raise(key): # SaaS运行版本,如非必要请勿修改 RUN_VER = os.getenv("RUN_VER", "open") # 蓝鲸SaaS平台URL,例如 http://paas.bking.com -BK_URL = "" +BK_URL = None APP_NAME = "BKFlow" RUN_VER_NAME = _("蓝鲸智云")