feat: 支持资料包多文件与zip导入

This commit is contained in:
2026-06-04 01:07:15 +08:00
parent 2b40ddc487
commit aa0a24fe5a
5 changed files with 198 additions and 20 deletions

View File

@@ -1,5 +1,7 @@
from django.core.files.uploadedfile import SimpleUploadedFile
from django.urls import reverse
from io import BytesIO
from zipfile import ZipFile
from apps.documents.forms import DocumentUploadForm
from apps.documents.models import SubmissionBatch, UploadedDocument
@@ -197,6 +199,34 @@ def test_document_list_supports_product_name_search(client, db):
assert "呼吸道合胞病毒核酸检测试剂盒" not in content
def test_document_list_supports_batch_id_search(client, db):
SubmissionBatch.objects.create(
batch_id="SUB-20260604-001",
product_name="产品A",
workflow_type="registration",
conversation_id="conv-001",
file_count=2,
page_count=12,
import_status="completed",
)
SubmissionBatch.objects.create(
batch_id="SUB-20260604-002",
product_name="产品B",
workflow_type="registration",
conversation_id="conv-002",
file_count=3,
page_count=20,
import_status="completed",
)
response = client.get(reverse("documents:list"), {"keyword": "SUB-20260604-002"})
content = response.content.decode("utf-8")
assert response.status_code == 200
assert "SUB-20260604-002" in content
assert "SUB-20260604-001" not in content
def test_import_submission_batch_marks_manual_review_when_product_names_conflict(db):
files = [
SimpleUploadedFile(
@@ -217,3 +247,50 @@ def test_import_submission_batch_marks_manual_review_when_product_names_conflict
assert batch.import_status == "review_required"
assert result["registration_overview_report"]["warnings"]
assert "产品名称来源冲突" in result["registration_overview_report"]["warnings"][0]
def test_upload_multiple_files_creates_single_submission_batch_and_multiple_documents(client, db):
application = SimpleUploadedFile(
"注册申请表.txt",
"产品名称:新型冠状病毒 2019-nCoV 核酸检测试剂盒".encode("utf-8"),
content_type="text/plain",
)
manual = SimpleUploadedFile(
"目标产品说明书.txt",
"产品名称:新型冠状病毒 2019-nCoV 核酸检测试剂盒".encode("utf-8"),
content_type="text/plain",
)
response = client.post(
reverse("documents:upload"),
{"scenario_id": "document_review", "files": [application, manual]},
)
assert response.status_code == 302
batch = SubmissionBatch.objects.get()
assert batch.file_count == 2
assert UploadedDocument.objects.filter(batch=batch).count() == 2
assert Conversation.objects.get().title == "新型冠状病毒 2019-nCoV 核酸检测试剂盒"
def test_import_submission_batch_supports_zip_package_and_preserves_relative_paths(db):
archive = BytesIO()
with ZipFile(archive, "w") as zip_file:
zip_file.writestr("CH1/注册申请表.txt", "产品名称产品A")
zip_file.writestr("CH1/目标产品说明书.txt", "产品名称产品A")
archive.seek(0)
package = SimpleUploadedFile(
"registration-package.zip",
archive.read(),
content_type="application/zip",
)
result = import_submission_batch("document_review", [package])
batch = SubmissionBatch.objects.get(batch_id=result["batch_id"])
documents = list(UploadedDocument.objects.filter(batch=batch).order_by("relative_path"))
assert batch.file_count == 2
assert [document.relative_path for document in documents] == [
"CH1/注册申请表.txt",
"CH1/目标产品说明书.txt",
]