fix(media): هیچ آپلودی هرگز متحرک ذخیره نمی‌شود — منبع چندفریمی (gif/ویدیو) همیشه به پوستر فریم اول می‌رسد؛ انیمیشن در کارت‌ها سوسو می‌زد

This commit is contained in:
aramesh-site deploy
2026-10-01 11:48:08 +00:00
parent 68863eb44e
commit 6f1f42ba7a
2 changed files with 37 additions and 76 deletions
+13 -5
View File
@@ -441,7 +441,7 @@ def test_upload_jpeg_converted_to_webp(auth_client, monkeypatch):
assert body["width"] == 2000 and body["height"] == 1000
def test_upload_animated_gif_becomes_animated_webp(auth_client, monkeypatch):
def test_upload_animated_gif_becomes_static_webp(auth_client, monkeypatch):
fake = _mock_storage(monkeypatch)
res = auth_client.post(
"/api/admin/upload",
@@ -455,7 +455,8 @@ def test_upload_animated_gif_becomes_animated_webp(auth_client, monkeypatch):
stored = next(iter(fake.objects.values()))
out = Image.open(io.BytesIO(stored))
assert out.format == "WEBP"
assert getattr(out, "n_frames", 1) == 2 # حرکت از بین نرفته
# هیچ آپلودی هرگز متحرک ذخیره نمی‌شود — پوستر فریم اول
assert getattr(out, "n_frames", 1) == 1
def test_upload_undecodable_file_rejected(auth_client, monkeypatch):
@@ -467,14 +468,14 @@ def test_upload_undecodable_file_rejected(auth_client, monkeypatch):
assert res.status_code == 415
def test_upload_video_becomes_animated_webp(auth_client, monkeypatch):
# ویدیو تنها با FFmpeg قابل پذیرش است — بدون آن ۴۱۵، با آن WebP متحرک
def test_upload_video_becomes_static_webp_poster(auth_client, monkeypatch):
# ویدیو تنها با FFmpeg قابل پذیرش است — بدون آن ۴۱۵، با آن پوستر تک‌فریمی WebP
import shutil as _shutil
import subprocess as _subprocess
import tempfile as _tempfile
import os as _os
_mock_storage(monkeypatch)
fake = _mock_storage(monkeypatch)
if _shutil.which("ffmpeg") is None:
res = auth_client.post(
"/api/admin/upload",
@@ -499,6 +500,13 @@ def test_upload_video_becomes_animated_webp(auth_client, monkeypatch):
)
assert res.status_code == 200, res.text
assert res.json()["content_type"] == "image/webp"
from PIL import Image
import io
stored = next(iter(fake.objects.values()))
out = Image.open(io.BytesIO(stored))
# ویدیو هرگز وب متحرک نمی‌شود — در کارت‌ها سوسو نمی‌زند
assert getattr(out, "n_frames", 1) == 1
def test_upload_without_name_uses_filename(auth_client, monkeypatch):