97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
import pytest
|
|
|
|
from review_agent.models import (
|
|
ApplicationFormFillBatch,
|
|
Conversation,
|
|
ExportedSummaryFile,
|
|
FileSummaryBatch,
|
|
RegulatoryIssue,
|
|
RegulatoryReviewBatch,
|
|
)
|
|
from review_agent.notifications.message_builder import absolute_result_url
|
|
from review_agent.notifications.workflow_adapters import (
|
|
build_application_form_fill_context,
|
|
build_file_summary_context,
|
|
build_regulatory_review_context,
|
|
)
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_file_summary_adapter_builds_summary(settings, django_user_model):
|
|
settings.PUBLIC_BASE_URL = "http://example.test"
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
batch = FileSummaryBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="FS-001",
|
|
status=FileSummaryBatch.Status.SUCCESS,
|
|
total_files=3,
|
|
success_files=2,
|
|
failed_files=1,
|
|
total_pages=15,
|
|
)
|
|
|
|
context = build_file_summary_context(batch)
|
|
|
|
assert context.workflow_type == "file_summary"
|
|
assert context.workflow_batch_no == "FS-001"
|
|
assert "异常" in "\n".join(context.summary_lines)
|
|
assert absolute_result_url(context.result_path).endswith(f"/api/review-agent/file-summary/{batch.pk}/status/")
|
|
|
|
|
|
def test_regulatory_review_adapter_builds_risk_summary(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
summary_batch = FileSummaryBatch.objects.create(conversation=conversation, user=user, batch_no="FS-RR")
|
|
batch = RegulatoryReviewBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_summary_batch=summary_batch,
|
|
batch_no="RR-001",
|
|
status=RegulatoryReviewBatch.Status.SUCCESS,
|
|
)
|
|
RegulatoryIssue.objects.create(
|
|
batch=batch,
|
|
category=RegulatoryIssue.Category.COMPLETENESS,
|
|
severity=RegulatoryIssue.Severity.BLOCKING,
|
|
title="缺少资料",
|
|
)
|
|
|
|
context = build_regulatory_review_context(batch)
|
|
|
|
assert context.workflow_type == "regulatory_review"
|
|
assert "阻断项 1" in "\n".join(context.summary_lines)
|
|
|
|
|
|
def test_application_form_fill_adapter_builds_export_and_conflict_summary(django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="会话")
|
|
summary_batch = FileSummaryBatch.objects.create(conversation=conversation, user=user, batch_no="FS-AFF")
|
|
batch = ApplicationFormFillBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_summary_batch=summary_batch,
|
|
batch_no="AFF-001",
|
|
status=ApplicationFormFillBatch.Status.PARTIAL_SUCCESS,
|
|
selected_templates=["registration_certificate"],
|
|
conflict_summary=[{"field": "product_name"}],
|
|
)
|
|
ExportedSummaryFile.objects.create(
|
|
batch=summary_batch,
|
|
workflow_type="application_form_fill",
|
|
workflow_batch_id=batch.pk,
|
|
export_category="filled_template",
|
|
export_type=ExportedSummaryFile.ExportType.WORD,
|
|
file_name="filled.docx",
|
|
storage_path="filled.docx",
|
|
)
|
|
|
|
context = build_application_form_fill_context(batch)
|
|
|
|
assert context.workflow_type == "application_form_fill"
|
|
assert "导出文件 1" in "\n".join(context.summary_lines)
|
|
assert "冲突字段 1" in "\n".join(context.summary_lines)
|