feat: 补齐DOCX精确页数识别与待复核策略
This commit is contained in:
@@ -4,6 +4,7 @@ from io import BytesIO
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import types
|
||||
import zipfile
|
||||
from zipfile import ZipFile
|
||||
|
||||
from apps.documents.forms import DocumentUploadForm
|
||||
@@ -418,7 +419,72 @@ def test_import_submission_batch_records_warnings_for_unsupported_zip_entries(db
|
||||
assert batch.file_count == 1
|
||||
assert batch.exception_count == 1
|
||||
assert "跳过不支持的文件" in warnings[0]
|
||||
assert "CH1/忽略图片.png" in warnings[0]
|
||||
|
||||
|
||||
def test_import_submission_batch_uses_exact_docx_page_count_from_metadata(db):
|
||||
archive = BytesIO()
|
||||
with zipfile.ZipFile(archive, "w") as docx_file:
|
||||
docx_file.writestr(
|
||||
"word/document.xml",
|
||||
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||
<w:body>
|
||||
<w:p><w:r><w:t>产品名称:新型冠状病毒 2019-nCoV 核酸检测试剂盒</w:t></w:r></w:p>
|
||||
</w:body>
|
||||
</w:document>""",
|
||||
)
|
||||
docx_file.writestr(
|
||||
"docProps/app.xml",
|
||||
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
|
||||
<Pages>7</Pages>
|
||||
</Properties>""",
|
||||
)
|
||||
archive.seek(0)
|
||||
file = SimpleUploadedFile(
|
||||
"CH1-目标产品说明书.docx",
|
||||
archive.read(),
|
||||
content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
)
|
||||
|
||||
result = import_submission_batch("document_review", [file])
|
||||
|
||||
batch = SubmissionBatch.objects.get(batch_id=result["batch_id"])
|
||||
document = UploadedDocument.objects.get(batch=batch)
|
||||
assert batch.page_count == 7
|
||||
assert document.page_count == 7
|
||||
assert document.page_count_confidence == "exact"
|
||||
assert batch.import_status == "completed"
|
||||
|
||||
|
||||
def test_import_submission_batch_marks_review_when_docx_page_count_cannot_be_precisely_detected(db):
|
||||
archive = BytesIO()
|
||||
with zipfile.ZipFile(archive, "w") as docx_file:
|
||||
docx_file.writestr(
|
||||
"word/document.xml",
|
||||
"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
||||
<w:body>
|
||||
<w:p><w:r><w:t>产品名称:新型冠状病毒 2019-nCoV 核酸检测试剂盒</w:t></w:r></w:p>
|
||||
</w:body>
|
||||
</w:document>""",
|
||||
)
|
||||
archive.seek(0)
|
||||
file = SimpleUploadedFile(
|
||||
"CH1-目标产品说明书.docx",
|
||||
archive.read(),
|
||||
content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
)
|
||||
|
||||
result = import_submission_batch("document_review", [file])
|
||||
|
||||
batch = SubmissionBatch.objects.get(batch_id=result["batch_id"])
|
||||
document = UploadedDocument.objects.get(batch=batch)
|
||||
warnings = result["registration_overview_report"]["warnings"]
|
||||
assert document.page_count_confidence == "estimated"
|
||||
assert document.needs_manual_review is True
|
||||
assert batch.import_status == "review_required"
|
||||
assert any("DOCX 页数无法精确统计" in warning for warning in warnings)
|
||||
|
||||
|
||||
def test_import_submission_batch_marks_failed_when_zip_has_no_supported_files(db):
|
||||
|
||||
Reference in New Issue
Block a user