feat(insta-lab): card_renderer with Jinja + Playwright (1080x1350)
This commit is contained in:
48
insta-lab/tests/test_card_renderer.py
Normal file
48
insta-lab/tests/test_card_renderer.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user