优化视频复刻和商品内容大小

This commit is contained in:
Azmat@qq.com
2026-08-28 18:42:28 +08:00
parent a618f02315
commit 6b6146e595
20 changed files with 1557 additions and 382 deletions
+66
View File
@@ -819,6 +819,20 @@ class FacetsProductsTests(TestCase):
data = self.client.get("/api/assets/facets/?tab=others").json()
self.assertEqual(data["products"], [])
def test_facets_products_newest_first(self):
from datetime import timedelta
from django.utils import timezone
from apps.products.models import Product
Asset.objects.create(
team=self.team, name="上身图2", asset_type="image", source="ai_generated",
category=Asset.Category.MODEL_TRYON, metadata={"product_id": str(self.p2.id)},
)
Product.objects.filter(id=self.p1.id).update(created_at=timezone.now() - timedelta(days=1))
data = self.client.get("/api/assets/facets/?tab=tryon").json()
self.assertEqual([p["id"] for p in data["products"]], [str(self.p2.id), str(self.p1.id)])
class SubmitReviewTests(TestCase):
"""手动兜底:灰盾点击 → 提交审核;只对送审类放行,非送审类 400。"""
@@ -927,3 +941,55 @@ class ReviewScopeTests(TestCase):
self.assertEqual(out["statuses"][str(proc.id)], "active")
sub.assert_called_once()
polled.assert_called_once()
class ImageSizeGuardTests(TestCase):
"""火山素材审核要求图片 300–6000 px。小图以前能一路存进商品库,
直到生成视频送审那一刻才炸([InvalidParameter.WidthTooSmall]) —— 报错离上传很远,
用户对不上号。改成入库前就挡住。"""
def _png(self, width, height):
from io import BytesIO
from PIL import Image
buf = BytesIO()
Image.new("RGB", (width, height), "white").save(buf, format="PNG")
return buf.getvalue()
def test_rejects_image_below_300px(self):
from apps.assets.image_guard import ImageTooSmallError, ensure_reviewable_image
with self.assertRaises(ImageTooSmallError) as ctx:
ensure_reviewable_image(self._png(120, 800), label="商品图")
self.assertIn("商品图", str(ctx.exception))
self.assertIn("300", str(ctx.exception))
self.assertIn("120×800", str(ctx.exception)) # 把实际尺寸写给用户,免得反复试
def test_rejects_image_above_6000px(self):
from apps.assets.image_guard import ImageTooSmallError, ensure_reviewable_image
with self.assertRaises(ImageTooSmallError):
ensure_reviewable_image(self._png(6400, 900))
def test_accepts_image_in_range_and_returns_size(self):
from apps.assets.image_guard import ensure_reviewable_image
self.assertEqual(ensure_reviewable_image(self._png(800, 1200)), (800, 1200))
def test_broken_file_is_rejected(self):
from apps.assets.image_guard import ImageTooSmallError, ensure_reviewable_image
with self.assertRaises(ImageTooSmallError):
ensure_reviewable_image(b"not-an-image")
def test_volcano_error_codes_are_humanized(self):
from apps.assets.review import humanize_submit_error
self.assertIn(
"图片太小",
humanize_submit_error("[InvalidParameter.WidthTooSmall] Width must be between 300px and 6000px."),
)
self.assertIn("格式不支持", humanize_submit_error("[InvalidParameter.InvalidImageFormat] bad"))
# 认不出的原样带出,不要吞掉
self.assertEqual(humanize_submit_error("Some brand new error"), "Some brand new error")