质检工单卡片右上角可上传/查看附件;第三方任务材料改为选填,校验与前端必填一并取消。 Co-authored-by: Cursor <cursoragent@cursor.com>
143 lines
4.4 KiB
Python
143 lines
4.4 KiB
Python
"""质检工单附件:序列化与第三方材料必填取消。"""
|
||
|
||
import os
|
||
|
||
# 避免导入 app 时 Settings 因缺 SECRET_KEY 失败
|
||
os.environ.setdefault(
|
||
"SECRET_KEY", "test-secret-key-for-qc-wo-attach-unit-tests-32c"
|
||
)
|
||
|
||
import unittest
|
||
from types import SimpleNamespace
|
||
from unittest.mock import MagicMock, patch
|
||
|
||
|
||
class TestQcWorkOrderAttachmentsDict(unittest.TestCase):
|
||
@classmethod
|
||
def setUpClass(cls):
|
||
# 先导入 qc_task 打破与 qc_work_order 的循环依赖
|
||
import app.crud.qc_task # noqa: F401
|
||
from app.crud import qc_work_order as wo_mod
|
||
|
||
cls.wo_mod = wo_mod
|
||
|
||
def _base_wo(self, **overrides):
|
||
wo = SimpleNamespace(
|
||
id="wo-1",
|
||
work_order_no="QC001",
|
||
work_order_type="inbound",
|
||
reception_id=None,
|
||
protocol_sample_id=None,
|
||
collection_protocol_id=None,
|
||
protocol_no="",
|
||
sample_code="S1",
|
||
reception_source="cell_storage",
|
||
qc_biz_type="inbound",
|
||
biz_type="",
|
||
cell_product_id=None,
|
||
external_target_code=None,
|
||
trigger_source="reception",
|
||
production_work_order_id=None,
|
||
production_task_id=None,
|
||
production_step_output_id=None,
|
||
infusion_schedule_id=None,
|
||
work_order_status="jxz",
|
||
conclusion=None,
|
||
has_lab="1",
|
||
has_third_party="0",
|
||
configured_time=None,
|
||
configured_by=None,
|
||
third_party_fee_total=None,
|
||
attachments=None,
|
||
remark=None,
|
||
create_time=None,
|
||
update_time=None,
|
||
)
|
||
for k, v in overrides.items():
|
||
setattr(wo, k, v)
|
||
return wo
|
||
|
||
def test_wo_to_dict_includes_attachments(self):
|
||
data = self.wo_mod._wo_to_dict(
|
||
self._base_wo(attachments="https://a/x.pdf, https://b/y.png")
|
||
)
|
||
self.assertEqual(data["attachments"], "https://a/x.pdf, https://b/y.png")
|
||
|
||
def test_wo_to_dict_attachments_default_empty(self):
|
||
data = self.wo_mod._wo_to_dict(self._base_wo(attachments=None, sample_code=""))
|
||
self.assertEqual(data["attachments"], "")
|
||
|
||
|
||
class TestRequireDsfjcAttachmentsOptional(unittest.TestCase):
|
||
def test_complete_without_third_party_attachments_ok(self):
|
||
from app.crud.qc_task import _require_dsfjc_attachments
|
||
|
||
task = SimpleNamespace(task_type="dsfjc", third_party_attachments="")
|
||
# 不再抛错
|
||
_require_dsfjc_attachments(task, for_status="ywc")
|
||
|
||
|
||
class TestUpdateQcWorkOrderAttachments(unittest.TestCase):
|
||
@patch("app.crud.qc_work_order.get_work_order")
|
||
def test_update_normalizes_and_sets_attachments(self, mock_get):
|
||
from app.crud.qc_work_order import update_qc_work_order
|
||
|
||
wo = SimpleNamespace(
|
||
id="wo-3",
|
||
work_order_type="inbound",
|
||
attachments=None,
|
||
remark=None,
|
||
work_order_status="jxz",
|
||
conclusion=None,
|
||
cell_product_id=None,
|
||
external_target_code=None,
|
||
update_by=None,
|
||
update_time=None,
|
||
)
|
||
mock_get.return_value = wo
|
||
db = MagicMock()
|
||
|
||
update_qc_work_order(
|
||
db,
|
||
"wo-3",
|
||
tenant_no="zkxw",
|
||
user_id="u1",
|
||
attachments=" https://a/1.pdf , https://b/2.pdf , ",
|
||
)
|
||
self.assertEqual(wo.attachments, "https://a/1.pdf,https://b/2.pdf")
|
||
self.assertEqual(wo.update_by, "u1")
|
||
db.add.assert_called()
|
||
db.flush.assert_called()
|
||
|
||
@patch("app.crud.qc_work_order.get_work_order")
|
||
def test_update_clear_attachments(self, mock_get):
|
||
from app.crud.qc_work_order import update_qc_work_order
|
||
|
||
wo = SimpleNamespace(
|
||
id="wo-4",
|
||
work_order_type="inbound",
|
||
attachments="https://a/1.pdf",
|
||
remark=None,
|
||
work_order_status="jxz",
|
||
conclusion=None,
|
||
cell_product_id=None,
|
||
external_target_code=None,
|
||
update_by=None,
|
||
update_time=None,
|
||
)
|
||
mock_get.return_value = wo
|
||
db = MagicMock()
|
||
|
||
update_qc_work_order(
|
||
db,
|
||
"wo-4",
|
||
tenant_no="zkxw",
|
||
user_id="u1",
|
||
attachments="",
|
||
)
|
||
self.assertIsNone(wo.attachments)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|