107 lines
3.5 KiB
Python
107 lines
3.5 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.policy.event_exception import (
|
|
WAIT_ADOPT,
|
|
WAIT_AIR_QUOTE,
|
|
WAIT_DEAL,
|
|
WAIT_PRODUCT_QUOTE,
|
|
conversation_of,
|
|
format_timeout_hours,
|
|
pick_app_targets,
|
|
pick_mentions,
|
|
timeout_code,
|
|
)
|
|
|
|
|
|
class TestTimeoutCode(unittest.TestCase):
|
|
def test_sales_unified(self) -> None:
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_ADOPT, business_line="SEA", transport_class="急件"),
|
|
"sea_sales",
|
|
)
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_DEAL, business_line="AIR", transport_class=""),
|
|
"air_sales",
|
|
)
|
|
self.assertEqual(
|
|
timeout_code(wait_kind="lost_reason", business_line="LAND", transport_class="急件"),
|
|
"land_sales",
|
|
)
|
|
|
|
def test_air_route(self) -> None:
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_AIR_QUOTE, business_line="AIR", transport_class=""),
|
|
"air_route",
|
|
)
|
|
|
|
def test_sea_and_land_product_class(self) -> None:
|
|
self.assertEqual(
|
|
timeout_code(
|
|
wait_kind=WAIT_PRODUCT_QUOTE, business_line="SEA", transport_class="Port to Port"
|
|
),
|
|
"sea_product_ptp",
|
|
)
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_PRODUCT_QUOTE, business_line="SEA", transport_class="其他"),
|
|
"sea_product_other",
|
|
)
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_PRODUCT_QUOTE, business_line="LAND", transport_class="急件"),
|
|
"land_hk_express",
|
|
)
|
|
self.assertEqual(
|
|
timeout_code(wait_kind=WAIT_PRODUCT_QUOTE, business_line="SEA", transport_class=""),
|
|
"",
|
|
)
|
|
|
|
def test_hours_format(self) -> None:
|
|
self.assertEqual(format_timeout_hours(0.25), "0.25")
|
|
self.assertEqual(format_timeout_hours(48), "48")
|
|
|
|
|
|
class TestMentions(unittest.TestCase):
|
|
def test_product_all_unanswered(self) -> None:
|
|
sales = {
|
|
"wecomId": "s1",
|
|
"name": "销售甲",
|
|
"roleCode": "sales",
|
|
"notifyEventException": 1,
|
|
}
|
|
members = [
|
|
{"wecomId": "p1", "name": "张三", "roleCode": "sea", "notifyEventException": 1},
|
|
{"wecomId": "p2", "name": "李四", "roleCode": "sea", "notifyEventException": 0},
|
|
{"wecomId": "s1", "name": "销售甲", "roleCode": "sales", "notifyEventException": 1},
|
|
]
|
|
hit = pick_mentions(
|
|
wait_kind=WAIT_PRODUCT_QUOTE,
|
|
sales=sales,
|
|
members=members,
|
|
business_line="SEA",
|
|
)
|
|
self.assertEqual([p["name"] for p in hit], ["张三", "李四"])
|
|
apps = pick_app_targets(hit)
|
|
self.assertEqual([p["wecomId"] for p in apps], ["p1"])
|
|
|
|
def test_adopt_is_private(self) -> None:
|
|
self.assertEqual(conversation_of(wait_kind=WAIT_ADOPT, collab_chat_id="wrxxx"), "private")
|
|
|
|
def test_deal_uses_group_when_present(self) -> None:
|
|
self.assertEqual(conversation_of(wait_kind=WAIT_DEAL, collab_chat_id="wrxxx"), "group")
|
|
self.assertEqual(conversation_of(wait_kind=WAIT_DEAL, collab_chat_id=""), "private")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|