AutoRpa/state_center/tests/test_yisaiqi_contract_draft.py

139 lines
4.7 KiB
Python

import json
from pathlib import Path
import pytest
from rpa_yisaiqi.contract_create_node import (
ContractCreateError,
ContractCreateInput,
PdfMergeUnsupported,
create_contract_in_contract_system,
)
from rpa_yisaiqi.contract_draft import load_contract_draft
from rpa_yisaiqi.pdf_utils import ensure_merged_pdf
def test_load_contract_draft_maps_full_contract_inputs(tmp_path):
draft_path = tmp_path / "contract-draft.json"
draft_path.write_text(
json.dumps(
{
"supplierName": "重庆亿昊药业",
"orderDate": "2026-08-11",
"sourceType": "YYC",
"templateType": "NON_FORMAT",
"templateName": "非格式--采购协议",
"customerCode": "CUST-001",
"customerName": "重庆亿昊药业",
"contractCategory": "采购协议",
"settlementType": "付款",
"contractBackground": "按订单自动起草采购协议",
"contractNature": "主合同",
"amountCurrency": "人民币",
"amount": "12000.50",
"contractEndDate": "2026-12-31",
"isMajorContract": "否",
"isPrepayment": "否",
"belongYear": "2026",
"paymentMethod": "承兑",
"paymentDays": "45",
"contractStatus": "正式合同",
"containsBloodProducts": "否",
"platformPdfPaths": ["C:/jobs/JOB-1/a.pdf", "C:/jobs/JOB-1/b.pdf"],
"goodsLines": [
{
"operationCode": "ADD",
"goodsCode": "YP-001",
"goodsName": "阿卡波糖片",
"approvalNo": "国药准字H00000001",
"spec": "50mg*30片",
"unit": "盒",
"quantity": 12,
}
],
},
ensure_ascii=False,
),
encoding="utf-8",
)
draft = load_contract_draft(draft_path)
assert draft.supplier_name == "重庆亿昊药业"
assert draft.template_type == "NON_FORMAT"
assert draft.template_name == "非格式--采购协议"
assert draft.customer_code == "CUST-001"
assert draft.customer_name == "重庆亿昊药业"
assert draft.contract_category == "采购协议"
assert draft.settlement_type == "付款"
assert draft.contract_background == "按订单自动起草采购协议"
assert draft.amount == "12000.50"
assert draft.contract_end_date == "2026-12-31"
assert draft.belong_year == "2026"
assert draft.payment_method == "承兑"
assert draft.contract_status == "正式合同"
assert draft.contains_blood_products == "否"
assert draft.platform_pdf_paths == ["C:/jobs/JOB-1/a.pdf", "C:/jobs/JOB-1/b.pdf"]
assert draft.goods_lines[0].goods_code == "YP-001"
def test_yyc_requires_pdf_inputs_before_contract_drafting(tmp_path):
draft_path = tmp_path / "draft.json"
draft_path.write_text(
json.dumps(
{
"supplierName": "重庆亿昊药业",
"orderDate": "2026-08-11",
"sourceType": "YYC",
"goodsLines": [],
"platformPdfPaths": [],
},
ensure_ascii=False,
),
encoding="utf-8",
)
spec = ContractCreateInput(
job_id="JOB-1",
supplier_name="重庆亿昊药业",
order_date="2026-08-11",
source_type="YYC",
draft_path=str(draft_path),
)
with pytest.raises(PdfMergeUnsupported):
create_contract_in_contract_system(spec)
def test_ensure_merged_pdf_uses_single_pdf_without_merge(tmp_path):
source = tmp_path / "one.pdf"
source.write_bytes(b"%PDF-1.4\n%one\n")
assert ensure_merged_pdf([str(source)], str(tmp_path / "merged.pdf")) == str(source)
def test_real_drafting_requires_yisaiqi_adapter_mapping(tmp_path):
draft_path = tmp_path / "draft.json"
draft_path.write_text(
json.dumps(
{
"supplierName": "小药药供应商",
"orderDate": "2026-08-11",
"sourceType": "XYY",
"goodsLines": [],
"platformPdfPaths": [],
},
ensure_ascii=False,
),
encoding="utf-8",
)
spec = ContractCreateInput(
job_id="JOB-1",
supplier_name="小药药供应商",
order_date="2026-08-11",
source_type="XYY",
draft_path=str(draft_path),
)
with pytest.raises(ContractCreateError, match="YiSaiQiBrowserAdapter"):
create_contract_in_contract_system(spec)