独立 biz_type=contract_processing,申请/缴费/出库与临床科研共用逻辑; 业务子类型支持胎盘冻干粉/脂肪外泌体/NK/MSC/其他自定义,并补充菜单与生产质检 Tab。 Co-authored-by: Cursor <cursoragent@cursor.com>
82 lines
2.9 KiB
Python
82 lines
2.9 KiB
Python
"""委托加工申请单:编号前缀、业务子类型校验、复用临床科研创建校验。"""
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from app.constants.research_category import validate_research_category
|
|
from app.crud import pilot_application as crud
|
|
|
|
|
|
class TestContractProcessingApplicationNo(unittest.TestCase):
|
|
@patch("app.crud.pilot_application.datetime")
|
|
def test_generate_application_no_contract_processing_prefix(self, mock_dt):
|
|
mock_dt.now.return_value.strftime.return_value = "20261123"
|
|
db = MagicMock()
|
|
mock_query = MagicMock()
|
|
db.query.return_value = mock_query
|
|
mock_query.filter.return_value = mock_query
|
|
mock_query.order_by.return_value = mock_query
|
|
mock_query.first.return_value = None
|
|
|
|
result = crud._generate_application_no(db, "zkxw", biz_type="contract_processing")
|
|
|
|
self.assertEqual(result, "WTJG202611230001")
|
|
|
|
|
|
class TestContractProcessingResearchCategory(unittest.TestCase):
|
|
def test_fixed_categories(self):
|
|
self.assertEqual(
|
|
validate_research_category("placenta_freeze_dried", required=True, biz_type="contract_processing"),
|
|
"placenta_freeze_dried",
|
|
)
|
|
self.assertEqual(
|
|
validate_research_category("nk", required=True, biz_type="contract_processing"),
|
|
"nk",
|
|
)
|
|
|
|
def test_custom_other_text(self):
|
|
self.assertEqual(
|
|
validate_research_category("自定义产品A", required=True, biz_type="contract_processing"),
|
|
"自定义产品A",
|
|
)
|
|
|
|
def test_clinical_codes_rejected_for_contract_processing(self):
|
|
with self.assertRaises(ValueError):
|
|
validate_research_category(
|
|
"bio_tech_clinical", required=True, biz_type="contract_processing"
|
|
)
|
|
|
|
def test_clinical_still_uses_legacy_codes(self):
|
|
self.assertEqual(
|
|
validate_research_category("bio_tech_clinical", required=True, biz_type="basic_experiment"),
|
|
"bio_tech_clinical",
|
|
)
|
|
with self.assertRaises(ValueError):
|
|
validate_research_category("nk", required=True, biz_type="basic_experiment")
|
|
|
|
|
|
class TestContractProcessingCreateValidation(unittest.TestCase):
|
|
def test_create_requires_customer_fields(self):
|
|
db = MagicMock()
|
|
data = {
|
|
"bizType": "contract_processing",
|
|
"researchCategory": "msc",
|
|
"channelId": "ch-1",
|
|
"projectTitle": "课题A",
|
|
"customerName": "",
|
|
"customerContact": "张三",
|
|
"customerPhone": "13800000000",
|
|
}
|
|
with self.assertRaises(ValueError) as ctx:
|
|
crud.create_application(
|
|
db,
|
|
data=data,
|
|
tenant_no="zkxw",
|
|
user_id="user-1",
|
|
dept_id="dept-1",
|
|
)
|
|
self.assertIn("客户名称", str(ctx.exception))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|