test(insta-lab): package 404/409 테스트 + 전체파일누락 409 가드

- /package 엔드포인트: asset DB 레코드는 있지만 모든 PNG 파일이
  디스크에 없는 경우 written=0 체크 후 HTTPException(409) 반환
- test_package_unknown_slate_404: 존재하지 않는 slate_id → 404 검증
- test_package_no_assets_409: asset 없는 slate → 409 검증 (기존 guard)
- test_package_no_assets_409: 파일 없는 asset만 있는 경우 → 409 검증 (신규 guard)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 13:01:39 +09:00
parent 3a9d6e986e
commit 1efe3d3a48
2 changed files with 26 additions and 0 deletions

View File

@@ -258,11 +258,13 @@ def download_package(slate_id: int):
if not assets:
raise HTTPException(409, "아직 렌더된 카드가 없습니다")
buf = io.BytesIO()
written = 0
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as z:
for a in assets:
fp = a["file_path"]
if os.path.exists(fp):
z.write(fp, arcname=f"{a['page_index']:02d}.png")
written += 1
caption = (slate.get("suggested_caption") or "").strip()
tags = slate.get("hashtags") or []
if isinstance(tags, str):
@@ -272,6 +274,8 @@ def download_package(slate_id: int):
tags = []
caption_full = caption + ("\n\n" + " ".join(tags) if tags else "")
z.writestr("caption.txt", caption_full)
if written == 0:
raise HTTPException(409, "렌더된 카드 파일이 없습니다")
buf.seek(0)
return StreamingResponse(buf, media_type="application/zip", headers={
"Content-Disposition": f'attachment; filename="insta_slate_{slate_id}.zip"'