"""库存数据看板月份与统计口径回归测试。""" import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] class InventoryBoardLogicTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.frontend = ROOT.joinpath('static', 'js', 'app.js').read_text(encoding='utf-8') cls.backend = ROOT.joinpath('routes', 'dashboard.py').read_text(encoding='utf-8') def test_month_is_dynamic_and_uses_shanghai_timezone(self): self.assertIn("timeZone: 'Asia/Shanghai'", self.frontend) self.assertIn('inventoryBoardCurrentMonth()', self.frontend) self.assertNotIn("monthInput.value = '2026-08'", self.frontend) def test_snapshot_is_limited_to_selected_month(self): self.assertIn( 'WHERE data_date >= %s AND data_date < %s', self.backend, ) def test_disabled_warehouses_and_all_warehouse_stockout_are_enforced(self): self.assertIn("active_warehouse_condition('id')", self.backend) self.assertIn('HAVING SUM(id.available_qty) <= 0', self.backend) self.assertIn('_stockout_codes.intersection_update(_sales_30.keys())', self.backend) self.assertNotIn('AND id.available_qty = 0', self.backend) def test_external_value_is_optional_override(self): self.assertIn('if key not in external_map', self.backend) self.assertNotIn("if value in ('', None):\n result[key] = 0", self.backend) def test_sku_thresholds_follow_visible_labels(self): self.assertIn("float(row['qty'] or 0) >= 30", self.backend) self.assertIn("float(row['qty'] or 0) >= 100", self.backend) self.assertIn("float(row['qty'] or 0) >= 200", self.backend) if __name__ == '__main__': unittest.main()