63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from app.services.pl_plan_archive_zip_export import (
|
|
sanitize_zip_segment,
|
|
build_attachment_filename,
|
|
first_row_no_by_plan_id,
|
|
build_hyperlink_formula,
|
|
parse_url_list,
|
|
collect_hazard_cert_items,
|
|
merge_plan_attachment_items,
|
|
)
|
|
|
|
|
|
def test_sanitize_zip_segment():
|
|
assert sanitize_zip_segment("装货·司机/A") == "装货·司机_A"
|
|
assert sanitize_zip_segment(" a ") == "a"
|
|
|
|
|
|
def test_build_attachment_filename():
|
|
name = build_attachment_filename(1, "装货·司机", "https://cdn.example/path/a.jpg")
|
|
assert name.startswith("01_装货·司机_")
|
|
assert name.endswith(".jpg")
|
|
|
|
|
|
def test_first_row_no_by_plan_id():
|
|
rows = [
|
|
{"planId": "p1", "rowNo": 1},
|
|
{"planId": "p1", "rowNo": 2},
|
|
{"planId": "p2", "rowNo": 3},
|
|
]
|
|
assert first_row_no_by_plan_id(rows) == {"p1": 1, "p2": 3}
|
|
|
|
|
|
def test_build_hyperlink_formula():
|
|
f = build_hyperlink_formula("附件/01_司机_ab12.jpg", "司机")
|
|
assert f.startswith('=HYPERLINK(')
|
|
assert "附件/01_司机_ab12.jpg" in f
|
|
|
|
|
|
def test_parse_url_list_csv_and_json():
|
|
assert parse_url_list("a.jpg,b.jpg") == ["a.jpg", "b.jpg"]
|
|
assert parse_url_list('["x.png","y.png"]') == ["x.png", "y.png"]
|
|
|
|
|
|
def test_collect_hazard_cert_items_labels():
|
|
class P:
|
|
product_name = "甲醇"
|
|
purchase_cert_url = "https://x/p.pdf"
|
|
transport_cert_url = None
|
|
legal_use_cert_url = "https://x/l1.pdf,https://x/l2.pdf"
|
|
|
|
items = collect_hazard_cert_items([P()])
|
|
labels = [i["label"] for i in items]
|
|
assert "购买证" in labels[0]
|
|
assert any("合法使用证明" in x for x in labels)
|
|
assert len(items) == 3
|
|
|
|
|
|
def test_merge_dedupes_url():
|
|
doc = [{"url": "https://a/1.jpg", "label": "司机"}]
|
|
haz = [{"url": "https://a/1.jpg", "label": "购买证"}]
|
|
merged = merge_plan_attachment_items(doc, haz)
|
|
assert len(merged) == 1
|
|
assert merged[0]["label"] == "司机"
|