from app.services.pl_plan_archive_zip_export import ( sanitize_zip_segment, build_attachment_filename, first_row_no_by_plan_id, build_hyperlink_formula, ) 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