52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
"""计划预测/待下单包材数量传递回归测试。"""
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
import routes.purchase as purchase
|
|
|
|
|
|
class PendingBomPackagingTestCase(unittest.TestCase):
|
|
def test_normalization_preserves_pre_and_post_packaging_quantities(self):
|
|
items = purchase._normalize_pending_bom_items([{
|
|
'material_code': ' MAT-001 ',
|
|
'material_name': '瓶子',
|
|
'bom_qty': '1.5',
|
|
'actual_quantity': '10000',
|
|
'pre_pack_qty': '6235',
|
|
'post_pack_qty': '-1265',
|
|
'pkg_remark': '测试',
|
|
}])
|
|
self.assertEqual(len(items), 1)
|
|
self.assertEqual(items[0]['material_code'], 'MAT-001')
|
|
self.assertEqual(items[0]['quantity'], 1.5)
|
|
self.assertEqual(items[0]['actual_quantity'], 10000)
|
|
self.assertEqual(items[0]['pre_pack_qty'], 6235)
|
|
self.assertEqual(items[0]['post_pack_qty'], -1265)
|
|
|
|
def test_missing_packaging_quantities_are_not_fabricated(self):
|
|
item = purchase._normalize_pending_bom_items([{
|
|
'material_code': 'MAT-002',
|
|
'actual_quantity': 5000,
|
|
}])[0]
|
|
self.assertNotIn('pre_pack_qty', item)
|
|
self.assertNotIn('post_pack_qty', item)
|
|
|
|
def test_sync_writes_explicit_pre_packaging_quantity(self):
|
|
with mock.patch.object(purchase, 'query') as query_mock:
|
|
purchase._sync_pending_pre_packaging('PRODUCT-1', [{
|
|
'material_code': 'MAT-001',
|
|
'pre_pack_qty': 9000,
|
|
'pkg_remark': '新数量',
|
|
}, {
|
|
'material_code': '成品_PRODUCT-1',
|
|
'pre_pack_qty': 123,
|
|
}])
|
|
query_mock.assert_called_once()
|
|
self.assertEqual(query_mock.call_args.args[1], (
|
|
'PRODUCT-1', 'MAT-001', 9000, '新数量', 9000, '新数量'
|
|
))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|