48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""仓库属性库存按编号规范化匹配的回归测试。"""
|
|
|
|
import unittest
|
|
from datetime import date
|
|
from unittest import mock
|
|
|
|
from services import inventory_calc
|
|
|
|
|
|
class InventoryPropertyMappingTest(unittest.TestCase):
|
|
def test_numeric_warehouse_codes_ignore_leading_zeroes(self):
|
|
with mock.patch.object(
|
|
inventory_calc,
|
|
"query",
|
|
side_effect=[
|
|
[{"warehouse_code": "035"}],
|
|
[{"d": date(2026, 10, 9)}],
|
|
[{"product_code": "POZ-MSG-1322-PDD", "total_qty": 4935}],
|
|
],
|
|
) as query:
|
|
result = inventory_calc.compute_product_inventory_by_property("云仓")
|
|
|
|
self.assertEqual(4935, result["POZ-MSG-1322-PDD"])
|
|
inventory_sql, params = query.call_args.args
|
|
self.assertIn("CAST(warehouse_code AS UNSIGNED)", inventory_sql)
|
|
self.assertEqual(("2026-10-09", 35), params)
|
|
|
|
def test_non_numeric_warehouse_codes_remain_exact_matches(self):
|
|
with mock.patch.object(
|
|
inventory_calc,
|
|
"query",
|
|
side_effect=[
|
|
[{"warehouse_code": "OVERSEAS-A"}],
|
|
[{"d": date(2026, 10, 9)}],
|
|
[{"product_code": "SKU-1", "total_qty": 7}],
|
|
],
|
|
) as query:
|
|
result = inventory_calc.compute_product_inventory_by_property("外仓")
|
|
|
|
self.assertEqual(7, result["SKU-1"])
|
|
inventory_sql, params = query.call_args.args
|
|
self.assertNotIn("CAST(warehouse_code AS UNSIGNED)", inventory_sql)
|
|
self.assertEqual(("2026-10-09", "OVERSEAS-A"), params)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|