216 lines
7.8 KiB
Python
216 lines
7.8 KiB
Python
"""
|
|
报价模板匹配单测:关键词 → 默认 → 双无。不连主账。
|
|
"""
|
|
|
|
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_broken_bracket_keyword_still_hits_sea(self) -> None:
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "s1",
|
|
"name": "海运报价单模板",
|
|
"bizType": "海运",
|
|
"keywords": ["[海运,整柜,FCL]"],
|
|
"isDefault": False,
|
|
},
|
|
],
|
|
business_line="SEA",
|
|
facts={"整柜或拼柜": "整柜", "目的港": "巴生西港"},
|
|
)
|
|
self.assertIsNotNone(hit)
|
|
self.assertEqual(hit.match_type, "keyword")
|
|
self.assertEqual(hit.name, "海运报价单模板")
|
|
|
|
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)
|
|
|
|
def test_land_pinche_not_stolen_by_generic_land_keyword(self) -> None:
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "hk",
|
|
"name": "中港",
|
|
"bizType": "陆运",
|
|
"keywords": ["中港", "陆运"],
|
|
"isDefault": False,
|
|
},
|
|
{
|
|
"templateId": "ltl",
|
|
"name": "国内拼车",
|
|
"bizType": "陆运",
|
|
"keywords": ["拼车", "零担"],
|
|
"isDefault": False,
|
|
},
|
|
{
|
|
"templateId": "d1",
|
|
"name": "陆运默认",
|
|
"bizType": "陆运",
|
|
"keywords": ["普件"],
|
|
"isDefault": True,
|
|
},
|
|
],
|
|
business_line="LAND",
|
|
facts={
|
|
"运输类型": "国内运输拼车",
|
|
"线路类别": "国内城配/拖车/打包",
|
|
"运输分类": "普件,常用线路/常规车型",
|
|
"起运港": "泉州市",
|
|
"目的港": "南京市",
|
|
},
|
|
)
|
|
self.assertIsNotNone(hit)
|
|
self.assertEqual(hit.match_type, "keyword")
|
|
self.assertEqual(hit.name, "国内拼车")
|
|
|
|
def test_land_cross_ftl_beats_domestic_ftl(self) -> None:
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "dom",
|
|
"name": "国内整车",
|
|
"bizType": "陆运",
|
|
"keywords": ["整车", "国内"],
|
|
"isDefault": False,
|
|
},
|
|
{
|
|
"templateId": "xb",
|
|
"name": "跨境整车",
|
|
"bizType": "陆运",
|
|
"keywords": ["跨境", "整车"],
|
|
"isDefault": False,
|
|
},
|
|
],
|
|
business_line="LAND",
|
|
facts={"运输类型": "跨境整车", "线路类别": "东南亚"},
|
|
)
|
|
self.assertIsNotNone(hit)
|
|
self.assertEqual(hit.name, "跨境整车")
|
|
|
|
def test_land_falls_back_to_default(self) -> None:
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "hk",
|
|
"name": "中港",
|
|
"bizType": "陆运",
|
|
"keywords": ["中港"],
|
|
"isDefault": False,
|
|
},
|
|
{
|
|
"templateId": "d1",
|
|
"name": "陆运默认",
|
|
"bizType": "陆运",
|
|
"keywords": ["急件"],
|
|
"isDefault": True,
|
|
},
|
|
],
|
|
business_line="LAND",
|
|
facts={"运输类型": "国内运输拼车", "运输分类": "普件,常用线路/常规车型"},
|
|
)
|
|
self.assertIsNotNone(hit)
|
|
self.assertEqual(hit.match_type, "default")
|
|
self.assertEqual(hit.name, "陆运默认")
|
|
|
|
def test_land_admin_keyword_domestic_lcl_matches_transport_type(self) -> None:
|
|
"""后台陆运拼车模板关键词是「国内拼车」,对得上字段「国内运输拼车」。"""
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "hk",
|
|
"name": "中港",
|
|
"bizType": "陆运",
|
|
"keywords": ["中港", "陆运"],
|
|
"isDefault": False,
|
|
},
|
|
{
|
|
"templateId": "ltl",
|
|
"name": "陆运国内运输拼车报价单",
|
|
"bizType": "陆运",
|
|
"keywords": ["国内拼车", "国内零担"],
|
|
"isDefault": False,
|
|
},
|
|
],
|
|
business_line="LAND",
|
|
facts={"运输类型": "国内运输拼车", "起运港": "广州", "目的港": "深圳"},
|
|
)
|
|
self.assertIsNotNone(hit)
|
|
self.assertEqual(hit.match_type, "keyword")
|
|
self.assertEqual(hit.name, "陆运国内运输拼车报价单")
|
|
|
|
def test_land_none_without_default(self) -> None:
|
|
hit = pick_quote_template(
|
|
templates=[
|
|
{
|
|
"templateId": "hk",
|
|
"name": "中港",
|
|
"bizType": "陆运",
|
|
"keywords": ["中港"],
|
|
"isDefault": False,
|
|
},
|
|
],
|
|
business_line="LAND",
|
|
facts={"运输类型": "国内运输拼车"},
|
|
)
|
|
self.assertIsNone(hit)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|