39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
"""包材订单到货批次不良品补填规则回归测试。"""
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
class PackagingArrivalDefectiveTest(unittest.TestCase):
|
|
def test_packaging_defective_allows_negative_and_over_arrival(self):
|
|
from routes.purchase import _arrival_batch_quantities
|
|
|
|
self.assertEqual((10, -3, True, True), _arrival_batch_quantities(
|
|
{'arrival_qty': '10', 'defective_qty': '-3'}, 'packaging'))
|
|
self.assertEqual((10, 30, True, True), _arrival_batch_quantities(
|
|
{'arrival_qty': '10', 'defective_qty': '30'}, 'packaging'))
|
|
|
|
def test_blank_defective_is_preserved_as_unfilled(self):
|
|
from routes.purchase import _arrival_batch_quantities
|
|
|
|
self.assertEqual((10, 0, True, False), _arrival_batch_quantities(
|
|
{'arrival_qty': '10', 'defective_qty': ''}, 'packaging'))
|
|
|
|
def test_other_order_types_keep_existing_validation(self):
|
|
from routes.purchase import _arrival_batch_quantities
|
|
|
|
with self.assertRaisesRegex(ValueError, '不能为负数'):
|
|
_arrival_batch_quantities({'arrival_qty': '10', 'defective_qty': '-1'}, 'domestic')
|
|
with self.assertRaisesRegex(ValueError, '不能大于到货数量'):
|
|
_arrival_batch_quantities({'arrival_qty': '10', 'defective_qty': '11'}, 'overseas')
|
|
|
|
def test_frontend_keeps_blank_and_only_validates_non_packaging_range(self):
|
|
source = Path(__file__).resolve().parents[1].joinpath('static/js/app.js').read_text(encoding='utf-8')
|
|
self.assertIn("defectiveRaw === '' ? ''", source)
|
|
self.assertIn("orderType !== 'packaging' && defectiveRaw !== ''", source)
|
|
self.assertIn("renderArrivalBatchStoredCell('number', 'batch-defective-qty'", source)
|
|
self.assertNotIn('min="0" class="batch-defective-qty"', source)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|