60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
import os
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
from app import db as db_module
|
|
from app import card_renderer
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_db_and_dirs(monkeypatch, tmp_path):
|
|
fd, path = tempfile.mkstemp(suffix=".db")
|
|
os.close(fd)
|
|
monkeypatch.setattr(db_module, "DB_PATH", path)
|
|
monkeypatch.setattr(card_renderer, "CARDS_DIR", str(tmp_path / "cards"))
|
|
db_module.init_db()
|
|
yield path
|
|
import gc
|
|
gc.collect()
|
|
for ext in ("", "-wal", "-shm"):
|
|
try:
|
|
os.remove(path + ext)
|
|
except OSError:
|
|
pass
|
|
|
|
|
|
def _seed_slate() -> int:
|
|
return db_module.add_card_slate({
|
|
"keyword": "테스트",
|
|
"category": "economy",
|
|
"status": "draft",
|
|
"cover_copy": {"headline": "커버 헤드라인", "body": "서브카피", "accent_color": "#0F62FE"},
|
|
"body_copies": [{"headline": f"본문 {i+1}", "body": f"내용 {i+1}"} for i in range(8)],
|
|
"cta_copy": {"headline": "마무리", "body": "감사합니다", "cta": "팔로우"},
|
|
})
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_render_slate_produces_ten_pngs(tmp_db_and_dirs):
|
|
sid = _seed_slate()
|
|
paths = await card_renderer.render_slate(sid)
|
|
assert len(paths) == 10
|
|
for p in paths:
|
|
assert os.path.exists(p)
|
|
assert os.path.getsize(p) > 1000 # > 1 KB sanity
|
|
db_module.update_slate_status(sid, "rendered")
|
|
assets = db_module.list_card_assets(sid)
|
|
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
|