50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""质检物料月初模板:字段校验纯函数单测。"""
|
|
import unittest
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
from app.crud.qc_material_month_template import _require_template_fields
|
|
|
|
|
|
class TestRequireTemplateFields(unittest.TestCase):
|
|
def _base(self, **overrides):
|
|
data = {
|
|
"materialCode": "QC-M-001",
|
|
"materialName": "试剂A",
|
|
"catalogNo": "CAT-1",
|
|
"batchNo": "B-1",
|
|
"manufacturer": "厂家X",
|
|
"unitPrice": 10.5,
|
|
"amount": 105,
|
|
"inQty": 10,
|
|
"expireDate": "2027-01-01",
|
|
}
|
|
data.update(overrides)
|
|
return data
|
|
|
|
def test_ok(self):
|
|
got = _require_template_fields(self._base())
|
|
self.assertEqual(got["material_code"], "QC-M-001")
|
|
self.assertEqual(got["material_name"], "试剂A")
|
|
self.assertEqual(got["catalog_no"], "CAT-1")
|
|
self.assertEqual(got["in_qty"], Decimal("10"))
|
|
self.assertEqual(got["expire_date"], date(2027, 1, 1))
|
|
|
|
def test_missing_catalog(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
_require_template_fields(self._base(catalogNo=""))
|
|
self.assertIn("货号", str(ctx.exception))
|
|
|
|
def test_qty_not_positive(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
_require_template_fields(self._base(inQty=0))
|
|
self.assertIn("入库数量", str(ctx.exception))
|
|
|
|
def test_missing_code_name(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
_require_template_fields(self._base(materialCode=""))
|
|
self.assertIn("物料编码", str(ctx.exception))
|
|
with self.assertRaises(ValueError) as ctx2:
|
|
_require_template_fields(self._base(materialName=""))
|
|
self.assertIn("物料名称", str(ctx2.exception))
|