Files
inquiry_robot/inquiry-agent/tests/test_activate_sheet_no_attach.py
T

122 lines
3.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
激活发群模版不得登记主账附件;正式有价出单必须登记。
验收:
- 激活路径 _render_and_send_sheet 默认 persist_attachment=False;
- 有价出单显式传 True;
- 确认落库 _persist_quote_sheet 传 True。
"""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import MagicMock
from agent.policy import sea_group_ops
class _Ledger:
def __init__(self) -> None:
self.calls: list[dict[str, Any]] = []
def render_quote(self, **kwargs: Any) -> dict[str, Any]:
self.calls.append(dict(kwargs))
return {
"ok": True,
"fileName": "WO1空运到港报价单",
"fileBase64": "UEsDBAoAAAAAA",
"objectKey": "inquiry/work-order-files/WO1.xlsx",
"attachmentSaved": bool(kwargs.get("persist_attachment")),
"templateId": "t1",
"templateName": "空运到港报价单",
}
def test_activate_send_does_not_persist_attachment(monkeypatch) -> None:
ledger = _Ledger()
flow = SimpleNamespace(ledger=ledger)
client = MagicMock()
client.send_group_file.return_value = {"ok": True}
monkeypatch.setattr(sea_group_ops, "group_client_of", lambda _f: client)
monkeypatch.setattr(
sea_group_ops,
"overlay_labeled_facts",
lambda **_k: {"filepath": "", "file_b64": "UEsDBAoAAAAAA"},
)
out = sea_group_ops._render_and_send_sheet(
flow=flow,
chat_id="chat-1",
work_order_no="WO202610170054",
facts={"weight_kg": "11"},
quote={},
sales_id="u1",
business_line="AIR",
)
assert out.get("ok") is True
assert len(ledger.calls) == 1
assert ledger.calls[0].get("persist_attachment") is False
def test_priced_send_persists_attachment(monkeypatch) -> None:
"""正式有价出单:群发 Excel 同时写后台附件(WO102 类缺附件回归)。"""
ledger = _Ledger()
flow = SimpleNamespace(ledger=ledger)
client = MagicMock()
client.send_group_file.return_value = {"ok": True}
monkeypatch.setattr(sea_group_ops, "group_client_of", lambda _f: client)
monkeypatch.setattr(
sea_group_ops,
"overlay_labeled_facts",
lambda **_k: {"filepath": "", "file_b64": "UEsDBAoAAAAAA"},
)
out = sea_group_ops._render_and_send_sheet(
flow=flow,
chat_id="chat-1",
work_order_no="WO202610170102",
facts={"weight_kg": "11"},
quote={"total": "9900", "currency": "CNY"},
sales_id="u1",
business_line="AIR",
persist_attachment=True,
)
assert out.get("ok") is True
assert len(ledger.calls) == 1
assert ledger.calls[0].get("persist_attachment") is True
def test_confirm_persist_quote_sheet_requests_attachment(monkeypatch) -> None:
ledger = _Ledger()
flow = SimpleNamespace(ledger=ledger)
monkeypatch.setattr(sea_group_ops, "_archive_file", lambda *_a, **_k: None)
ticket = {
"work_order_no": "WO202610170054",
"business_line": "AIR",
"facts": {"weight_kg": "11"},
"collab_facts": {},
"sales_wecom_id": "u1",
"sales_name": "张三",
}
sess = SimpleNamespace(
work_order_no="WO202610170054",
facts={"weight_kg": "11"},
collab_facts={},
sender_id="u1",
)
sea_group_ops._persist_quote_sheet(
flow=flow,
ticket=ticket,
sess=sess,
quote={"total": "100"},
sender_id="u1",
business_line="AIR",
)
assert len(ledger.calls) == 1
assert ledger.calls[0].get("persist_attachment") is True