feat: support contract template replace and delete
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from fastapi_common.fastapi_common_web.exception.LeauditException import LeauditException
|
||||
from fastapi_modules.fastapi_leaudit.services.impl.contractTemplateServiceImpl import ContractTemplateServiceImpl
|
||||
|
||||
|
||||
@@ -11,6 +14,9 @@ class _EmptyMappingResult:
|
||||
def all(self):
|
||||
return []
|
||||
|
||||
def first(self):
|
||||
return None
|
||||
|
||||
|
||||
class _FakeSession:
|
||||
def __init__(self):
|
||||
@@ -66,3 +72,95 @@ def test_contract_template_search_category_stats_binds_expanding_scope_params():
|
||||
assert fake_session.executed_sql._bindparams["visible_regions"].expanding is True
|
||||
assert fake_session.executed_params["visible_tenant_codes"] == ["PROVINCIAL", "PUBLIC", "MZ"]
|
||||
assert fake_session.executed_params["visible_regions"] == ["省级", "公共", "梅州"]
|
||||
|
||||
|
||||
def test_contract_template_upload_scope_allows_global_manager_with_tenant():
|
||||
service = ContractTemplateServiceImpl()
|
||||
|
||||
tenant_code, tenant_name, region = service._resolve_upload_scope(
|
||||
{
|
||||
"id": 1,
|
||||
"area": "梅州",
|
||||
"tenant_code": "MZ",
|
||||
"tenant_name": "梅州",
|
||||
"tenant_scope_value": "梅州",
|
||||
"is_global": True,
|
||||
"can_manage": True,
|
||||
"is_area_admin": False,
|
||||
},
|
||||
"梅州",
|
||||
"MZ",
|
||||
)
|
||||
|
||||
assert tenant_code == "MZ"
|
||||
assert tenant_name == "梅州"
|
||||
assert region == "梅州"
|
||||
|
||||
|
||||
def test_contract_template_upload_scope_rejects_non_manager():
|
||||
service = ContractTemplateServiceImpl()
|
||||
|
||||
with pytest.raises(LeauditException):
|
||||
service._resolve_upload_scope(
|
||||
{
|
||||
"id": 2,
|
||||
"area": "梅州",
|
||||
"tenant_code": "MZ",
|
||||
"tenant_name": "梅州",
|
||||
"tenant_scope_value": "梅州",
|
||||
"is_global": False,
|
||||
"can_manage": False,
|
||||
"is_area_admin": False,
|
||||
},
|
||||
"梅州",
|
||||
"MZ",
|
||||
)
|
||||
|
||||
|
||||
def test_contract_template_detail_binds_expanding_scope_params():
|
||||
service = ContractTemplateServiceImpl()
|
||||
fake_session = _FakeSession()
|
||||
|
||||
async def noop_ensure_schema(session):
|
||||
return None
|
||||
|
||||
async def fake_user_context(current_user_id, session):
|
||||
return {
|
||||
"id": current_user_id,
|
||||
"area": "梅州",
|
||||
"tenant_code": "MZ",
|
||||
"tenant_name": "梅州",
|
||||
"tenant_scope_value": "梅州",
|
||||
"is_global": False,
|
||||
"can_manage": True,
|
||||
"is_area_admin": True,
|
||||
}
|
||||
|
||||
service._ensureContractTemplateSchema = noop_ensure_schema
|
||||
service._getCurrentUserContext = fake_user_context
|
||||
|
||||
with patch(
|
||||
"fastapi_modules.fastapi_leaudit.services.impl.contractTemplateServiceImpl.GetAsyncSession",
|
||||
return_value=_FakeSessionContext(fake_session),
|
||||
):
|
||||
result = asyncio.run(service.GetTemplateDetail(32, 5))
|
||||
|
||||
assert result is None
|
||||
assert fake_session.executed_sql._bindparams["visible_tenant_codes"].expanding is True
|
||||
assert fake_session.executed_sql._bindparams["visible_regions"].expanding is True
|
||||
assert fake_session.executed_params["visible_tenant_codes"] == ["PROVINCIAL", "PUBLIC", "MZ"]
|
||||
assert fake_session.executed_params["visible_regions"] == ["省级", "公共", "梅州"]
|
||||
|
||||
|
||||
def test_contract_template_detail_permission_does_not_fallback_to_list_permission():
|
||||
from fastapi_modules.fastapi_leaudit.controllers.contractTemplateController import ContractTemplateController
|
||||
|
||||
controller = ContractTemplateController()
|
||||
|
||||
class FakePermissionService:
|
||||
async def CheckPermission(self, user_id, permission_key):
|
||||
return permission_key == "contract_template:list:read"
|
||||
|
||||
controller.PermissionService = FakePermissionService()
|
||||
|
||||
assert asyncio.run(controller._check_permission(5, ["contract_template:detail:read"])) is False
|
||||
|
||||
Reference in New Issue
Block a user