feat(regulatory): 增加法规核查基础服务
This commit is contained in:
44
tests/test_regulatory_completeness.py
Normal file
44
tests/test_regulatory_completeness.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import pytest
|
||||
|
||||
from review_agent.models import Conversation, FileSummaryBatch, FileSummaryItem
|
||||
from review_agent.regulatory_review.services.completeness_check import run_completeness_check
|
||||
from review_agent.regulatory_review.services.rule_loader import load_rule_file
|
||||
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_completeness_check_matches_existing_files_and_reports_missing(django_user_model):
|
||||
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-CHECK",
|
||||
status=FileSummaryBatch.Status.SUCCESS,
|
||||
)
|
||||
FileSummaryItem.objects.create(
|
||||
batch=batch,
|
||||
file_index=1,
|
||||
file_name="产品技术要求.docx",
|
||||
file_type="docx",
|
||||
relative_path="产品技术要求.docx",
|
||||
storage_path="x/product.docx",
|
||||
)
|
||||
FileSummaryItem.objects.create(
|
||||
batch=batch,
|
||||
file_index=2,
|
||||
file_name="说明书.docx",
|
||||
file_type="docx",
|
||||
relative_path="说明书.docx",
|
||||
storage_path="x/ifu.docx",
|
||||
)
|
||||
|
||||
findings = run_completeness_check(batch, load_rule_file())
|
||||
|
||||
titles = [finding.title for finding in findings]
|
||||
assert "缺少注册检验报告" in titles
|
||||
assert "缺少产品技术要求" not in titles
|
||||
missing = next(finding for finding in findings if finding.rule_code == "registration_test_report")
|
||||
assert missing.severity == "blocking"
|
||||
assert missing.category == "completeness"
|
||||
14
tests/test_regulatory_consistency.py
Normal file
14
tests/test_regulatory_consistency.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from review_agent.regulatory_review.services.consistency_check import run_consistency_check
|
||||
|
||||
|
||||
def test_consistency_check_reports_product_name_mismatch():
|
||||
document_texts = {
|
||||
"说明书.docx": "产品名称:甲胎蛋白检测试剂盒\n型号规格:20人份/盒\n预期用途:定量检测AFP",
|
||||
"技术要求.docx": "产品名称:乙肝表面抗原检测试剂盒\n型号规格:20人份/盒\n预期用途:定量检测AFP",
|
||||
}
|
||||
|
||||
findings = run_consistency_check(document_texts)
|
||||
|
||||
assert len(findings) == 1
|
||||
assert findings[0].category == "consistency"
|
||||
assert "产品名称" in findings[0].title
|
||||
26
tests/test_regulatory_storage.py
Normal file
26
tests/test_regulatory_storage.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
|
||||
from review_agent.models import Conversation, FileSummaryBatch, RegulatoryReviewBatch
|
||||
from review_agent.regulatory_review.storage import save_artifact
|
||||
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_save_artifact_writes_file_and_records_hash(settings, tmp_path, django_user_model):
|
||||
settings.MEDIA_ROOT = tmp_path
|
||||
user = django_user_model.objects.create_user(username="owner", password="pass")
|
||||
conversation = Conversation.objects.create(user=user, title="会话")
|
||||
summary = FileSummaryBatch.objects.create(conversation=conversation, user=user, batch_no="FS-OK")
|
||||
batch = RegulatoryReviewBatch.objects.create(
|
||||
conversation=conversation,
|
||||
user=user,
|
||||
source_summary_batch=summary,
|
||||
batch_no="RR-ART",
|
||||
)
|
||||
|
||||
artifact = save_artifact(batch, name="raw.json", content='{"ok": true}', artifact_type="json")
|
||||
|
||||
assert artifact.content_hash
|
||||
assert artifact.storage_path.endswith("raw.json")
|
||||
assert (tmp_path / "regulatory_review" / "work" / "RR-ART" / "raw.json").exists()
|
||||
13
tests/test_regulatory_structure.py
Normal file
13
tests/test_regulatory_structure.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from review_agent.regulatory_review.services.rule_loader import load_rule_file
|
||||
from review_agent.regulatory_review.services.structure_check import run_structure_check
|
||||
|
||||
|
||||
def test_structure_check_reports_missing_instruction_sections():
|
||||
document_texts = {
|
||||
"说明书.docx": "产品名称:甲胎蛋白检测试剂盒\n样本要求:血清样本\n有效期:12个月"
|
||||
}
|
||||
|
||||
findings = run_structure_check(document_texts, load_rule_file())
|
||||
|
||||
assert any(finding.rule_code == "instructions_for_use:储存条件" for finding in findings)
|
||||
assert all("样本要求" not in finding.title for finding in findings)
|
||||
24
tests/test_regulatory_text_extract.py
Normal file
24
tests/test_regulatory_text_extract.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from pathlib import Path
|
||||
|
||||
from review_agent.regulatory_review.services.text_extract import extract_text
|
||||
|
||||
|
||||
def test_extract_text_reads_plain_text(tmp_path):
|
||||
path = tmp_path / "说明书.txt"
|
||||
path.write_text("产品名称:甲胎蛋白检测试剂盒\n储存条件:2-8℃", encoding="utf-8")
|
||||
|
||||
result = extract_text(path)
|
||||
|
||||
assert "甲胎蛋白" in result.text
|
||||
assert result.status == "success"
|
||||
assert result.content_hash
|
||||
|
||||
|
||||
def test_extract_text_reports_unsupported_file(tmp_path):
|
||||
path = tmp_path / "image.png"
|
||||
path.write_bytes(b"png")
|
||||
|
||||
result = extract_text(path)
|
||||
|
||||
assert result.status == "unsupported"
|
||||
assert result.text == ""
|
||||
Reference in New Issue
Block a user