feat: 试用过程中的细节优化

This commit is contained in:
2026-09-13 22:19:16 +08:00
parent dbb2bb80bd
commit 897e5585c0
40 changed files with 1156 additions and 257 deletions
+21 -1
View File
@@ -1,8 +1,10 @@
"""单图导出响应头回归测试。"""
from __future__ import annotations
import io
import sys
import unittest
import zipfile
from pathlib import Path
from unittest.mock import AsyncMock, patch
@@ -10,7 +12,7 @@ SERVER_DIR = Path(__file__).resolve().parents[1]
if str(SERVER_DIR) not in sys.path:
sys.path.insert(0, str(SERVER_DIR))
from api.export import ExportImageItem, export_image
from api.export import ExportImageItem, ExportImagesRequest, export_image, export_images
class ExportImageTests(unittest.IsolatedAsyncioTestCase):
@@ -27,6 +29,24 @@ class ExportImageTests(unittest.IsolatedAsyncioTestCase):
self.assertIn('filename="_____-__.png"', disposition)
self.assertIn("filename*=UTF-8''%E5%B0%BA%E5%AF%B8%E6%A0%87%E6%B3%A8%E5%9B%BE-%E8%93%9D%E8%89%B2.png", disposition)
async def test_flat_export_places_generated_images_in_product_root(self) -> None:
request = ExportImagesRequest(
title="商品",
flat=True,
images=[
ExportImageItem(url="https://example.com/single.png", groupName="单张生图", key="single"),
ExportImageItem(url="https://example.com/suite.png", groupName="套图结果", key="suite"),
],
)
with patch("api.export._download", new=AsyncMock(return_value=(b"image", "image/png"))):
response = await export_images(request)
payload = b"".join([chunk async for chunk in response.body_iterator])
self.assertEqual(
sorted(zipfile.ZipFile(io.BytesIO(payload)).namelist()),
["商品/single.png", "商品/suite.png"],
)
if __name__ == "__main__":
unittest.main()