Extract pure mutual-exclusion helper to avoid circular imports in unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""临时质检对象:系统产品 / 外部编号互斥归一化。"""
|
|
|
|
import unittest
|
|
|
|
from app.crud.temp_qc_target import resolve_temp_qc_target
|
|
|
|
|
|
class TestResolveTempQcTarget(unittest.TestCase):
|
|
def test_cell_product_only(self):
|
|
cp, ext = resolve_temp_qc_target(
|
|
cell_product_id=" pid-1 ", external_target_code=" "
|
|
)
|
|
self.assertEqual(cp, "pid-1")
|
|
self.assertIsNone(ext)
|
|
|
|
def test_external_only(self):
|
|
cp, ext = resolve_temp_qc_target(
|
|
cell_product_id="", external_target_code=" EXT-1 "
|
|
)
|
|
self.assertIsNone(cp)
|
|
self.assertEqual(ext, "EXT-1")
|
|
|
|
def test_both_raises(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
resolve_temp_qc_target(
|
|
cell_product_id="pid", external_target_code="EXT"
|
|
)
|
|
self.assertIn("不能同时", str(ctx.exception))
|
|
|
|
def test_neither_raises(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
resolve_temp_qc_target(cell_product_id="", external_target_code="")
|
|
self.assertIn("质检对象", str(ctx.exception))
|
|
|
|
def test_external_too_long(self):
|
|
with self.assertRaises(ValueError) as ctx:
|
|
resolve_temp_qc_target(
|
|
cell_product_id="", external_target_code="x" * 65
|
|
)
|
|
self.assertIn("64", str(ctx.exception))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|