39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""质检物料入库编号:RK + YYYYMMDD + 3位序号。"""
|
|
import unittest
|
|
from datetime import date
|
|
|
|
from app.crud.qc_material_stock_in_no import (
|
|
format_stock_in_no,
|
|
max_seq_from_stock_in_nos,
|
|
next_stock_in_nos,
|
|
)
|
|
|
|
|
|
class TestFormatStockInNo(unittest.TestCase):
|
|
def test_format(self):
|
|
self.assertEqual(format_stock_in_no(date(2026, 8, 19), 1), "RK20260819001")
|
|
self.assertEqual(format_stock_in_no(date(2026, 8, 19), 12), "RK20260819012")
|
|
self.assertEqual(format_stock_in_no(date(2026, 8, 19), 999), "RK20260819999")
|
|
|
|
|
|
class TestMaxSeq(unittest.TestCase):
|
|
def test_empty(self):
|
|
self.assertEqual(max_seq_from_stock_in_nos("RK20260819", []), 0)
|
|
|
|
def test_parses_matching_prefix(self):
|
|
nos = ["RK20260819001", "RK20260819007", "OTHER", "RK20260818099"]
|
|
self.assertEqual(max_seq_from_stock_in_nos("RK20260819", nos), 7)
|
|
|
|
def test_ignores_bad_suffix(self):
|
|
nos = ["RK20260819ABC", "RK20260819100"]
|
|
self.assertEqual(max_seq_from_stock_in_nos("RK20260819", nos), 100)
|
|
|
|
|
|
class TestNextStockInNos(unittest.TestCase):
|
|
def test_allocates_contiguous(self):
|
|
got = next_stock_in_nos(date(2026, 8, 19), count=3, existing_nos=["RK20260819002"])
|
|
self.assertEqual(got, ["RK20260819003", "RK20260819004", "RK20260819005"])
|
|
|
|
def test_zero_count(self):
|
|
self.assertEqual(next_stock_in_nos(date(2026, 8, 19), count=0, existing_nos=[]), [])
|