From 5a79ce60db1ef29a58b7c1000756f3681d087ad2 Mon Sep 17 00:00:00 2001 From: iSecloud <869820505@qq.com> Date: Wed, 6 Sep 2023 19:48:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/test_exec_actuator_script.py | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/dbm-ui/backend/tests/flow/components/collections/mysql/test_exec_actuator_script.py b/dbm-ui/backend/tests/flow/components/collections/mysql/test_exec_actuator_script.py index b6dbd01d65..38497da9e2 100644 --- a/dbm-ui/backend/tests/flow/components/collections/mysql/test_exec_actuator_script.py +++ b/dbm-ui/backend/tests/flow/components/collections/mysql/test_exec_actuator_script.py @@ -10,7 +10,7 @@ """ import logging -from typing import Type +from typing import List, Type import mock import pytest @@ -23,6 +23,8 @@ from backend.flow.plugins.components.collections.mysql.exec_actuator_script import ExecuteDBActuatorScriptComponent from backend.flow.utils.mysql.mysql_act_playload import MysqlActPayload from backend.flow.utils.mysql.mysql_context_dataclass import SingleApplyAutoContext +from backend.tests.flow.components.collections.base import BaseComponentPatcher as Patcher +from backend.tests.flow.components.collections.mysql.test_mysql_db_meta import TestMySQLDBMetaComponent from backend.tests.flow.components.collections.mysql.utils import MySQLSingleApplyComponentTest from backend.tests.mock_data.components import cc from backend.tests.mock_data.components.dbconfig import DBConfigApiMock @@ -34,8 +36,23 @@ class TestExecActuatorScriptComponent(MySQLSingleApplyComponentTest, TestCase): def component_cls(self) -> Type[Component]: - with mock.patch(target="backend.flow.utils.mysql.mysql_act_playload.DBConfigApi", new=DBConfigApiMock): - return ExecuteDBActuatorScriptComponent + return ExecuteDBActuatorScriptComponent + + def get_patchers(self) -> List[Patcher]: + patchers = super(MySQLSingleApplyComponentTest, self).get_patchers() + patchers.extend( + [ + Patcher( + target="backend.flow.utils.mysql.mysql_act_playload.DBConfigApi", + new=DBConfigApiMock, + ), + Patcher( + target="backend.flow.utils.base.payload_handler.DBConfigApi", + new=DBConfigApiMock, + ), + ] + ) + return patchers def to_mock_path_list(self): path_list = super(TestExecActuatorScriptComponent, self).to_mock_path_list() @@ -44,8 +61,7 @@ def to_mock_path_list(self): @classmethod def _set_trans_data(cls) -> None: - with mock.patch(target="backend.flow.utils.mysql.mysql_act_playload.DBConfigApi", new=DBConfigApiMock): - cls.trans_data = SingleApplyAutoContext(new_ip=cc.NORMAL_IP) + cls.trans_data = SingleApplyAutoContext(new_ip=cc.NORMAL_IP) @classmethod def _set_kwargs(cls) -> None: