feat: upgrade客服多店铺分流、批量报价与稳定性防护
This commit is contained in:
66
tests/test_batch_quote_reply_format.py
Normal file
66
tests/test_batch_quote_reply_format.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import unittest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from core.pydantic_ai_agent import CustomerMessage, CustomerServiceAgent
|
||||
|
||||
|
||||
class BatchQuoteReplyFormatTest(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_batch_reply_contains_per_image_and_options(self):
|
||||
agent = CustomerServiceAgent()
|
||||
cid = "__batch_quote_case__"
|
||||
st = agent._get_conversation_state(cid)
|
||||
st.pending_image_urls = ["https://img.alicdn.com/a.jpg", "https://img.alicdn.com/b.jpg"]
|
||||
st.pending_requirements = ["去背景", "加急"]
|
||||
|
||||
msg = CustomerMessage(
|
||||
msg_id="m-batch-1",
|
||||
acc_id="test_shop",
|
||||
msg="发完了,统一报价",
|
||||
from_id=cid,
|
||||
from_name="t",
|
||||
cy_id=cid,
|
||||
acc_type="AliWorkbench",
|
||||
msg_type=0,
|
||||
cy_name="t",
|
||||
goods_name="专业找图",
|
||||
goods_order="",
|
||||
)
|
||||
|
||||
fake_r1 = {
|
||||
"complexity": "normal",
|
||||
"reason": "常规处理",
|
||||
"price_min": 15,
|
||||
"price_max": 25,
|
||||
"price_suggest": 20,
|
||||
"feasibility": "yes",
|
||||
"risk": "low",
|
||||
"aspect_ratio": "1:1",
|
||||
"perspective": "no",
|
||||
}
|
||||
fake_r2 = {
|
||||
"complexity": "complex",
|
||||
"reason": "细节较多",
|
||||
"price_min": 20,
|
||||
"price_max": 30,
|
||||
"price_suggest": 25,
|
||||
"feasibility": "yes",
|
||||
"risk": "low",
|
||||
"aspect_ratio": "1:1",
|
||||
"perspective": "no",
|
||||
}
|
||||
|
||||
with patch("image.image_analyzer.image_analyzer.analyze", new=AsyncMock(side_effect=[fake_r1, fake_r2])):
|
||||
with patch("core.workflow.workflow.image_analysis_result", new=AsyncMock(return_value=None)):
|
||||
res = await agent._quote_pending_images(st, msg)
|
||||
|
||||
self.assertFalse(res.get("need_transfer", False))
|
||||
reply = res.get("reply", "")
|
||||
self.assertIn("图1", reply)
|
||||
self.assertIn("图2", reply)
|
||||
self.assertIn("可选", reply)
|
||||
self.assertIn("打包", reply)
|
||||
self.assertIn("共", reply)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
Reference in New Issue
Block a user