Skip to content

Commit

Permalink
尝试修改单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiyanghai committed Sep 23, 2024
1 parent 72f49bd commit 3f68f43
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions sql/test_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
ArchiveConfig,
WorkflowAudit,
WorkflowAuditSetting,
WorkflowAuditDetail,
)
from sql.tests import User

from datetime import timedelta, datetime

class TestArchiver(TestCase):
"""
Expand Down Expand Up @@ -79,6 +80,13 @@ def setUp(self):
create_user="",
create_user_display="",
)
self.audit_detail = WorkflowAuditDetail.objects.create(
audit_id=self.audit_flow.id,
audit_user="",
audit_time= self.now - timedelta(days=1),
audit_status=WorkflowStatus.PASSED,
remark="",
)
self.sys_config = SysConfig()
self.client = Client()

Expand Down Expand Up @@ -248,17 +256,17 @@ def test_archive_apply_auto_pass(self, mock_generate_setting):
assert archive_config.status == WorkflowStatus.PASSED

@patch("sql.utils.workflow_audit.AuditV2.operate")
@patch("sql.archiver.async_task")
def test_archive_audit(self, _async_task, mock_operate):
@patch("sql.notify.notify_for_audit.apply_async")
def test_archive_audit(self, mock_apply_async, mock_operate):
"""
测试审核归档实例数据
:return:
"""
mock_operate.return_value = None
data = {
"archive_id": self.archive_apply.id,
"audit_status": WorkflowStatus.PASSED,
"audit_remark": "xxxx",
"audit_status": self.audit_detail.audit_status,
"audit_remark": self.audit_detail.remark,
}
# operate 被 patch 了, 这里强制设置一下, 走一下流程
self.audit_flow.current_status = WorkflowStatus.PASSED
Expand All @@ -272,16 +280,13 @@ def test_archive_audit(self, _async_task, mock_operate):
assert self.archive_apply.state == True
assert self.archive_apply.status == WorkflowStatus.PASSED

@patch("sql.archiver.async_task")
def test_add_archive_task(self, _async_task):
"""
测试添加异步归档任务
:return:
"""
add_archive_task()
@patch('sql.archiver.add_archive_task.apply_async')
def test_add_archive_task(self, mock_apply_async):
# 调用 add.apply_async
add_archive_task.apply_async()

@patch("sql.archiver.async_task")
def test_add_archive(self, _async_task):
@patch("sql.archiver.archive.apply_async")
def test_add_archive(self, mock_apply_async):
"""
测试执行归档任务
:return:
Expand Down

0 comments on commit 3f68f43

Please sign in to comment.