完善组织树操作与空响应处理

This commit is contained in:
汤学会
2026-06-15 04:24:46 +08:00
parent 9b60aa3e0d
commit 867fc3beee
9 changed files with 701 additions and 19 deletions
@@ -398,6 +398,32 @@ class SystemPermissionManagementTest(unittest.TestCase):
self.assertEqual(tree[0].children[0].parent_id, self.company.id)
self.assertEqual(tree[0].children[0].node_type, "BRANCH")
def test_create_org_node_allows_company_direct_department(self) -> None:
from app.schemas.system_permissions import OrgNodeCreate
from app.services.system_permissions import create_org_node, build_org_tree
direct_department = create_org_node(
self.db,
OrgNodeCreate(
parent_id=self.company.id,
node_type="DEPARTMENT",
node_label="总公司直属部门",
dept_code="DIRECT-DEPT",
dept_type="ADMIN",
manager_employee_id=None,
sort_no=1,
remark=None,
status="ACTIVE",
),
)
tree = build_org_tree(self.db)
self.assertEqual(direct_department.parent_id, self.company.id)
self.assertEqual(direct_department.node_type, "DEPARTMENT")
self.assertTrue(
any(child.node_label == "总公司直属部门" and child.node_type == "DEPARTMENT" for child in tree[0].children)
)
def test_create_org_node_rejects_invalid_child_level(self) -> None:
from fastapi import HTTPException
from app.schemas.system_permissions import OrgNodeCreate
@@ -408,9 +434,9 @@ class SystemPermissionManagementTest(unittest.TestCase):
self.db,
OrgNodeCreate(
parent_id=self.company.id,
node_type="DEPARTMENT",
node_label="错误部门",
dept_code="BAD-DEPT",
node_type="GROUP",
node_label="错误小组",
dept_code="BAD-GROUP",
dept_type="ADMIN",
manager_employee_id=None,
sort_no=1,
@@ -419,7 +445,7 @@ class SystemPermissionManagementTest(unittest.TestCase):
),
)
self.assertEqual(ctx.exception.status_code, 400)
self.assertIn("总公司下只能新增分公司", str(ctx.exception.detail))
self.assertIn("总公司下只能新增分公司或直属部门", str(ctx.exception.detail))
def test_delete_org_node_rejects_nodes_with_children_or_bound_employees(self) -> None:
from fastapi import HTTPException