feat: 支持7z资料包导入
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.urls import reverse
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import types
|
||||
from zipfile import ZipFile
|
||||
|
||||
from apps.documents.forms import DocumentUploadForm
|
||||
@@ -294,3 +297,40 @@ def test_import_submission_batch_supports_zip_package_and_preserves_relative_pat
|
||||
"CH1/注册申请表.txt",
|
||||
"CH1/目标产品说明书.txt",
|
||||
]
|
||||
|
||||
|
||||
def test_import_submission_batch_supports_7z_package_and_preserves_relative_paths(db, monkeypatch, tmp_path):
|
||||
package = SimpleUploadedFile(
|
||||
"registration-package.7z",
|
||||
b"fake-7z-bytes",
|
||||
content_type="application/x-7z-compressed",
|
||||
)
|
||||
|
||||
class FakeSevenZipFile:
|
||||
def __init__(self, _file_obj, mode="r"):
|
||||
self.mode = mode
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def extractall(self, path):
|
||||
target = Path(path)
|
||||
(target / "CH1").mkdir(parents=True, exist_ok=True)
|
||||
(target / "CH1" / "注册申请表.txt").write_text("产品名称:产品A", encoding="utf-8")
|
||||
(target / "CH1" / "目标产品说明书.txt").write_text("产品名称:产品A", encoding="utf-8")
|
||||
|
||||
fake_module = types.SimpleNamespace(SevenZipFile=FakeSevenZipFile)
|
||||
monkeypatch.setitem(sys.modules, "py7zr", fake_module)
|
||||
|
||||
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",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user