fix: 修改一下生图的 bug

This commit is contained in:
2026-08-31 21:56:48 +08:00
parent 2a667b4f3b
commit 8b54f7ed1e
14 changed files with 636 additions and 47 deletions
+32
View File
@@ -0,0 +1,32 @@
"""单图导出响应头回归测试。"""
from __future__ import annotations
import sys
import unittest
from pathlib import Path
from unittest.mock import AsyncMock, patch
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
class ExportImageTests(unittest.IsolatedAsyncioTestCase):
async def test_chinese_filename_uses_rfc5987_header(self) -> None:
image = ExportImageItem(
url="https://example.com/image.png",
key="尺寸标注图",
variantName="蓝色",
)
with patch("api.export._download", new=AsyncMock(return_value=(b"image", "image/png"))):
response = await export_image(image)
disposition = response.headers["content-disposition"]
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)
if __name__ == "__main__":
unittest.main()