Skip to content

Commit

Permalink
补充工单详情的单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoQuote committed Nov 21, 2023
1 parent b09bde0 commit 83e4bb7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
13 changes: 11 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from pytest_mock import MockFixture
from django.contrib.auth.models import Group

from common.utils.const import WorkflowStatus
from sql.models import (
Expand Down Expand Up @@ -133,11 +134,19 @@ def setup_sys_config(db):


@pytest.fixture
def fake_generate_audit_setting(mocker: MockFixture):
def create_auth_group(db):
auth_group = Group.objects.create(name="test_group")
yield auth_group
auth_group.delete()


@pytest.fixture
def fake_generate_audit_setting(mocker: MockFixture, super_user, create_auth_group):
super_user.groups.add(create_auth_group)
mock_generate_audit_setting = mocker.patch.object(AuditV2, "generate_audit_setting")
fake_audit_setting = AuditSetting(
auto_pass=False,
audit_auth_groups=[123],
audit_auth_groups=[create_auth_group.id],
)
mock_generate_audit_setting.return_value = fake_audit_setting
yield mock_generate_audit_setting
Expand Down
24 changes: 24 additions & 0 deletions sql/test_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pytest_django.asserts import assertTemplateUsed, assertContains

from sql.utils.workflow_audit import AuditV2


def test_get_sql_workflow(
sql_workflow,
fake_generate_audit_setting,
super_user,
admin_client,
create_auth_group,
):
sql_workflow, _ = sql_workflow
audit = AuditV2(workflow=sql_workflow)
audit.create_audit()
audit.workflow.save()
response = admin_client.get(f"/detail/{sql_workflow.id}/")
assert response.status_code == 200
assertTemplateUsed(response, "detail.html")
# 展示审批人用户名
assert (
response.context["current_audit_auth_group"]
== f"{create_auth_group.name}: {super_user.username}"
)
4 changes: 2 additions & 2 deletions sql/utils/workflow_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ def get_workflow_applicant(workflow_id, workflow_type):
except Exception:
raise Exception("当前审批auth_group_id不存在,请检查并清洗历史数据")
if (
auth_group_users([audit_auth_group], group_id)
user.is_superuser
or auth_group_users([audit_auth_group], group_id)
.filter(id=user.id)
.exists()
or user.is_superuser == 1
):
if workflow_type == 1:
if user.has_perm("sql.query_review"):
Expand Down

0 comments on commit 83e4bb7

Please sign in to comment.