Files
certificate-system/backend/tests/test_certificate_templates.py
2026-08-13 18:06:05 +08:00

34 lines
1.2 KiB
Python

from datetime import date
from types import SimpleNamespace
from app.services.certificate_templates import (
CLASSIC_TEMPLATE_CODE,
PRACTICE_CAMP_TEMPLATE_CODE,
get_certificate_template,
list_certificate_templates,
)
from app.services.pdf import render_certificate_image
def test_builtin_certificate_templates_have_assets():
templates = list_certificate_templates()
assert {item.code for item in templates} == {CLASSIC_TEMPLATE_CODE, PRACTICE_CAMP_TEMPLATE_CODE}
assert all(item.asset_path.exists() for item in templates)
def test_practice_camp_template_renders_four_dynamic_values():
certificate = SimpleNamespace(
template_code=PRACTICE_CAMP_TEMPLATE_CODE,
course_start_date=date(2026, 3, 1),
course_end_date=date(2026, 8, 31),
issue_date=date(2026, 9, 5),
)
learner = SimpleNamespace(current_name="张晓慧")
rendered = render_certificate_image(certificate, learner, None)
template = get_certificate_template(PRACTICE_CAMP_TEMPLATE_CODE)
assert rendered.size == (3437, 2551)
assert template.dynamic_fields == ("姓名", "课程开始日期", "课程结束日期", "发证日期")