33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""单图导出响应头回归测试。"""
|
|
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()
|