Files
DEMO-AGENT/tests/test_application_form_fill_template_repository.py

61 lines
2.3 KiB
Python

import pytest
from review_agent.application_form_fill.services.template_config import load_template_config
from review_agent.application_form_fill.services.template_repository import (
TemplateUnavailableError,
copy_template_to_batch,
resolve_source_template,
)
from review_agent.application_form_fill.services.template_select import select_templates
from review_agent.models import (
ApplicationFormFillArtifact,
ApplicationFormFillBatch,
Conversation,
FileSummaryBatch,
)
pytestmark = pytest.mark.django_db
def test_resolve_source_template_finds_registration_docx():
config = load_template_config()
specs, _risk_notes = select_templates(config, ["registration_certificate"], "首次注册")
path = resolve_source_template(specs[0], config)
assert path.exists()
assert path.name == "中华人民共和国医疗器械注册证(体外诊断试剂)(格式).docx"
def test_copy_template_to_batch_creates_artifact(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-REPO")
batch = ApplicationFormFillBatch.objects.create(
conversation=conversation,
user=user,
source_summary_batch=summary,
batch_no="AFF-REPO",
work_dir=str(tmp_path / "aff" / "AFF-REPO"),
)
config = load_template_config()
specs, _risk_notes = select_templates(config, ["registration_certificate"], "首次注册")
artifact = copy_template_to_batch(specs[0], batch, config)
assert artifact.artifact_type == ApplicationFormFillArtifact.ArtifactType.TEMPLATE_COPY
assert artifact.file_format == "docx"
assert artifact.content_hash
assert artifact.metadata["template_code"] == "registration_certificate"
assert artifact.storage_path.startswith(batch.work_dir)
def test_doc_template_without_working_docx_is_unavailable():
config = load_template_config()
specs, _risk_notes = select_templates(config, ["change_registration"], "变更注册")
with pytest.raises(TemplateUnavailableError):
resolve_source_template(specs[0], config)