feat/insta-design-importer #7

Merged
gahusb merged 11 commits from feat/insta-design-importer into main 2026-05-18 00:28:53 +09:00
2 changed files with 19 additions and 0 deletions
Showing only changes of commit 2915f2b697 - Show all commits

View File

@@ -6,6 +6,7 @@ import json
import logging import logging
import os import os
import tempfile import tempfile
from pathlib import Path
from typing import List from typing import List
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
@@ -67,6 +68,13 @@ async def render_slate(slate_id: int, template: str = "default/card.html.j2") ->
if not slate: if not slate:
raise ValueError(f"slate {slate_id} not found") raise ValueError(f"slate {slate_id} not found")
env = _env() env = _env()
# template 파일이 없으면 default로 폴백 (INSTA_DEFAULT_THEME가 import 안 된 theme이면 안전)
template_full = Path(_resolve_template_dir()) / template
if not template_full.exists():
logger.warning("Template '%s' 없음 → 'default/card.html.j2'로 폴백", template)
template = "default/card.html.j2"
tmpl = env.get_template(template) tmpl = env.get_template(template)
pages = _build_pages(slate) pages = _build_pages(slate)
out_dir = _slate_dir(slate_id) out_dir = _slate_dir(slate_id)

View File

@@ -46,3 +46,14 @@ async def test_render_slate_produces_ten_pngs(tmp_db_and_dirs):
db_module.update_slate_status(sid, "rendered") db_module.update_slate_status(sid, "rendered")
assets = db_module.list_card_assets(sid) assets = db_module.list_card_assets(sid)
assert {a["page_index"] for a in assets} == set(range(1, 11)) assert {a["page_index"] for a in assets} == set(range(1, 11))
@pytest.mark.asyncio
async def test_render_falls_back_to_default_when_theme_html_missing(tmp_db_and_dirs):
"""존재하지 않는 theme HTML 지정 시 default/card.html.j2로 폴백, 정상 PNG 생성."""
sid = _seed_slate()
paths = await card_renderer.render_slate(sid, template="ghost_theme/card.html.j2")
assert len(paths) == 10
for p in paths:
assert os.path.exists(p)
assert os.path.getsize(p) > 1000