Skip to content

Commit

Permalink
fix: 修复单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Sep 6, 2023
1 parent 0d7a011 commit 5a79ce6
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

import logging
from typing import Type
from typing import List, Type

import mock
import pytest
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit 5a79ce6

Please sign in to comment.