feat: 支持rar资料包导入
This commit is contained in:
@@ -111,6 +111,21 @@ def test_document_upload_form_builds_scenario_choices():
|
||||
assert "quality_analysis" in choice_values
|
||||
|
||||
|
||||
def test_document_upload_form_accepts_rar_package():
|
||||
form = DocumentUploadForm(
|
||||
data={"scenario_id": "knowledge_qa"},
|
||||
files={
|
||||
"file": SimpleUploadedFile(
|
||||
"registration-package.rar",
|
||||
b"fake-rar-bytes",
|
||||
content_type="application/vnd.rar",
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
assert form.is_valid()
|
||||
|
||||
|
||||
def test_index_failure_message_is_visible_on_document_list(client, db, monkeypatch):
|
||||
document = UploadedDocument.objects.create(
|
||||
scenario_id="knowledge_qa",
|
||||
@@ -336,6 +351,54 @@ def test_import_submission_batch_supports_7z_package_and_preserves_relative_path
|
||||
]
|
||||
|
||||
|
||||
def test_import_submission_batch_supports_rar_package_and_preserves_relative_paths(db, monkeypatch):
|
||||
package = SimpleUploadedFile(
|
||||
"registration-package.rar",
|
||||
b"fake-rar-bytes",
|
||||
content_type="application/vnd.rar",
|
||||
)
|
||||
|
||||
class FakeRarInfo:
|
||||
def __init__(self, filename, is_dir=False):
|
||||
self.filename = filename
|
||||
self._is_dir = is_dir
|
||||
|
||||
def is_dir(self):
|
||||
return self._is_dir
|
||||
|
||||
class FakeRarFile:
|
||||
def __init__(self, _file_obj):
|
||||
self.entries = {
|
||||
"CH1/注册申请表.txt": "产品名称:产品A".encode("utf-8"),
|
||||
"CH1/目标产品说明书.txt": "产品名称:产品A".encode("utf-8"),
|
||||
}
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def infolist(self):
|
||||
return [FakeRarInfo(name) for name in self.entries]
|
||||
|
||||
def read(self, name):
|
||||
return self.entries[name]
|
||||
|
||||
fake_module = types.SimpleNamespace(RarFile=FakeRarFile)
|
||||
monkeypatch.setitem(sys.modules, "rarfile", 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",
|
||||
]
|
||||
|
||||
|
||||
def test_import_submission_batch_records_warnings_for_unsupported_zip_entries(db):
|
||||
archive = BytesIO()
|
||||
with ZipFile(archive, "w") as zip_file:
|
||||
|
||||
Reference in New Issue
Block a user