feat(regulatory): 增加整改复核闭环
This commit is contained in:
133
tests/test_regulatory_rectification.py
Normal file
133
tests/test_regulatory_rectification.py
Normal file
@@ -0,0 +1,133 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
from review_agent.models import (
|
||||
Conversation,
|
||||
FileSummaryBatch,
|
||||
FileSummaryItem,
|
||||
RegulatoryArtifact,
|
||||
RegulatoryIssue,
|
||||
RegulatoryReviewBatch,
|
||||
)
|
||||
from review_agent.regulatory_review.services.export import build_markdown_report, build_result_payload
|
||||
from review_agent.regulatory_review.services.rectification_review import review_missing_issues
|
||||
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def _make_review_batch(user):
|
||||
conversation = Conversation.objects.create(user=user, title="会话")
|
||||
original_summary = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-ORIGINAL",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
batch = RegulatoryReviewBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
source_summary_batch=original_summary,
|
||||
batch_no="RR-ORIGINAL",
|
||||
status=RegulatoryReviewBatch.Status.SUCCESS,
|
||||
)
|
||||
return conversation, original_summary, batch
|
||||
|
||||
|
||||
def test_start_full_package_review_creates_new_traceable_batch(client, settings, tmp_path, django_user_model):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
settings.REGULATORY_REVIEW_ASYNC = False
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation, _original_summary, original_batch = _make_review_batch(user)
|
||||
new_summary = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-NEW",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
client.force_login(user)
|
||||
|
||||
response = client.post(
|
||||
reverse("regulatory_review_start_full_review", args=[original_batch.pk]),
|
||||
data=json.dumps({"file_summary_batch_id": new_summary.pk}),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
new_batch = RegulatoryReviewBatch.objects.exclude(pk=original_batch.pk).get()
|
||||
assert new_batch.source_summary_batch == new_summary
|
||||
assert new_batch.condition_json["source_review_batch_id"] == original_batch.pk
|
||||
assert new_batch.condition_json["regenerated_from"]["batch_no"] == "RR-ORIGINAL"
|
||||
|
||||
|
||||
def test_review_missing_issues_updates_status_and_writes_record(settings, tmp_path, django_user_model):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation, _original_summary, batch = _make_review_batch(user)
|
||||
issue = RegulatoryIssue.objects.create(
|
||||
batch=batch,
|
||||
rule_code="attachment4_5_3_label",
|
||||
category=RegulatoryIssue.Category.COMPLETENESS,
|
||||
severity=RegulatoryIssue.Severity.HIGH,
|
||||
title="缺少标签样稿",
|
||||
suggestion="请补充标签样稿。",
|
||||
)
|
||||
supplement = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-SUPPLEMENT",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
FileSummaryItem.objects.create(
|
||||
batch=supplement,
|
||||
file_index=1,
|
||||
directory_level="5. 产品说明书和标签样稿",
|
||||
file_name="标签样稿.pdf",
|
||||
file_type="pdf",
|
||||
relative_path="5.3 标签样稿/标签样稿.pdf",
|
||||
storage_path="x/label.pdf",
|
||||
)
|
||||
|
||||
record = review_missing_issues(batch=batch, issue_ids=[issue.pk], file_summary_batch=supplement)
|
||||
|
||||
issue.refresh_from_db()
|
||||
assert issue.status == RegulatoryIssue.Status.REVIEW_PASSED
|
||||
assert record["items"][0]["status"] == "review_passed"
|
||||
assert RegulatoryArtifact.objects.filter(batch=batch, name__startswith="review_record").exists()
|
||||
|
||||
|
||||
def test_missing_issue_review_endpoint_and_report_output(client, settings, tmp_path, django_user_model):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation, _original_summary, batch = _make_review_batch(user)
|
||||
issue = RegulatoryIssue.objects.create(
|
||||
batch=batch,
|
||||
rule_code="attachment4_6_quality_system",
|
||||
category=RegulatoryIssue.Category.COMPLETENESS,
|
||||
severity=RegulatoryIssue.Severity.HIGH,
|
||||
title="缺少质量管理体系文件",
|
||||
suggestion="请补充质量管理体系文件。",
|
||||
)
|
||||
supplement = FileSummaryBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
batch_no="FS-SUPPLEMENT",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
client.force_login(user)
|
||||
|
||||
response = client.post(
|
||||
reverse("regulatory_review_review_issues", args=[batch.pk]),
|
||||
data=json.dumps({"issue_ids": [issue.pk], "file_summary_batch_id": supplement.pk}),
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
issue.refresh_from_db()
|
||||
payload = build_result_payload(batch)
|
||||
markdown = build_markdown_report(batch)
|
||||
assert response.status_code == 200
|
||||
assert issue.status == RegulatoryIssue.Status.REVIEW_FAILED
|
||||
assert payload["review_records"][0]["file_summary_batch_no"] == "FS-SUPPLEMENT"
|
||||
assert "复核记录" in markdown
|
||||
Reference in New Issue
Block a user