""" 报价模板匹配单测:关键词 → 默认 → 双无。不连主账。 """ from __future__ import annotations import os import sys import unittest ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) if ROOT not in sys.path: sys.path.insert(0, ROOT) from agent.quote_templates.match import FAIL_MESSAGE, pick_quote_template class QuoteTemplateMatchTests(unittest.TestCase): def test_keyword_beats_default(self) -> None: hit = pick_quote_template( templates=[ {"templateId": "d1", "name": "默认空运", "bizType": "空运", "keywords": ["欧洲"], "isDefault": True}, {"templateId": "k1", "name": "洛杉矶专线", "bizType": "空运", "keywords": ["洛杉矶"], "isDefault": False}, ], business_line="AIR", facts={"目的港": "洛杉矶", "品名": "普货"}, ) self.assertIsNotNone(hit) self.assertEqual(hit.match_type, "keyword") self.assertEqual(hit.name, "洛杉矶专线") def test_default_when_no_keyword(self) -> None: hit = pick_quote_template( templates=[ {"templateId": "d1", "name": "默认空运", "bizType": "空运", "keywords": ["欧洲"], "isDefault": True}, {"templateId": "k1", "name": "洛杉矶专线", "bizType": "空运", "keywords": ["洛杉矶"], "isDefault": False}, ], business_line="空运", facts={"目的港": "纽约"}, ) self.assertIsNotNone(hit) self.assertEqual(hit.match_type, "default") self.assertEqual(hit.name, "默认空运") def test_none_when_empty(self) -> None: hit = pick_quote_template( templates=[ {"templateId": "k1", "name": "洛杉矶专线", "bizType": "空运", "keywords": ["洛杉矶"], "isDefault": False}, ], business_line="AIR", facts={"目的港": "纽约"}, ) self.assertIsNone(hit) self.assertIn("IT运维", FAIL_MESSAGE) def test_sea_ignored_for_air(self) -> None: hit = pick_quote_template( templates=[ {"templateId": "s1", "name": "海运默认", "bizType": "海运", "keywords": ["洛杉矶"], "isDefault": True}, ], business_line="AIR", facts={"目的港": "洛杉矶"}, ) self.assertIsNone(hit) if __name__ == "__main__": unittest.main()