110 lines
3.8 KiB
Python
110 lines
3.8 KiB
Python
import pytest
|
|
from django.db import IntegrityError
|
|
|
|
from review_agent.models import (
|
|
Conversation,
|
|
ExportedSummaryFile,
|
|
FileAttachment,
|
|
RegulatoryInfoPackageArtifact,
|
|
RegulatoryInfoPackageBatch,
|
|
RegulatoryInfoPackageNotificationRecord,
|
|
WorkflowNodeRun,
|
|
)
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_regulatory_info_package_batch_defaults(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
attachment = FileAttachment.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
original_name="目标产品说明书.docx",
|
|
storage_path="uploads/instruction.docx",
|
|
)
|
|
|
|
batch = RegulatoryInfoPackageBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_attachment=attachment,
|
|
batch_no="RIP-20260610153000-abcdef",
|
|
source_file_name=attachment.original_name,
|
|
source_storage_path=attachment.storage_path,
|
|
)
|
|
|
|
assert batch.status == RegulatoryInfoPackageBatch.Status.PENDING
|
|
assert batch.output_zip_name == "第1章 监管信息(预生成版).zip"
|
|
assert batch.generated_files == []
|
|
assert batch.missing_fields == []
|
|
assert batch.llm_only_fields == []
|
|
assert batch.conflict_fields == []
|
|
assert batch.risk_notes == []
|
|
assert batch.adapter_summary == {}
|
|
assert str(batch) == "RIP-20260610153000-abcdef"
|
|
|
|
|
|
def test_regulatory_info_package_artifact_and_notification(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
batch = RegulatoryInfoPackageBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="RIP-20260610153100-abcdef",
|
|
)
|
|
|
|
artifact = RegulatoryInfoPackageArtifact.objects.create(
|
|
batch=batch,
|
|
artifact_type=RegulatoryInfoPackageArtifact.ArtifactType.ZIP_PACKAGE,
|
|
file_format=RegulatoryInfoPackageArtifact.FileFormat.ZIP,
|
|
name="主下载包",
|
|
file_name="第1章 监管信息(预生成版).zip",
|
|
storage_path="media/regulatory_info_package/package.zip",
|
|
)
|
|
notification = RegulatoryInfoPackageNotificationRecord.objects.create(
|
|
batch=batch,
|
|
recipient=user,
|
|
export_ids=[1, 2],
|
|
message_summary="材料包已生成",
|
|
send_status=RegulatoryInfoPackageNotificationRecord.SendStatus.SUCCESS,
|
|
)
|
|
|
|
assert artifact.metadata == {}
|
|
assert artifact.is_deleted is False
|
|
assert notification.channel == RegulatoryInfoPackageNotificationRecord.Channel.MOCK
|
|
assert notification.retry_count == 0
|
|
|
|
|
|
def test_exported_summary_file_supports_zip_type():
|
|
values = {value for value, _label in ExportedSummaryFile.ExportType.choices}
|
|
|
|
assert "zip" in values
|
|
|
|
|
|
def test_workflow_node_run_unique_for_workflow_batch(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
batch = RegulatoryInfoPackageBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="RIP-20260610153200-abcdef",
|
|
)
|
|
|
|
WorkflowNodeRun.objects.create(
|
|
workflow_type="regulatory_info_package",
|
|
workflow_batch_id=batch.pk,
|
|
node_group="regulatory_info_package",
|
|
node_code="prepare",
|
|
node_name="准备资料",
|
|
)
|
|
|
|
with pytest.raises(IntegrityError):
|
|
WorkflowNodeRun.objects.create(
|
|
workflow_type="regulatory_info_package",
|
|
workflow_batch_id=batch.pk,
|
|
node_group="regulatory_info_package",
|
|
node_code="prepare",
|
|
node_name="准备资料",
|
|
)
|