Merge branch 'refactor/backend-architecture' into development

This commit is contained in:
yangshilin
2026-03-18 17:18:23 +08:00
parent 2070a03d35
commit 48b70e1350
266 changed files with 12386 additions and 9690 deletions

View File

@@ -4,14 +4,15 @@ from unittest.mock import AsyncMock, patch, MagicMock
from PIL import Image
from api.services.pdf_service import PDFService
from api.services import pdf_service as pdf_service_module
from app.features.memoir.pdf_service import PDFService
import app.features.memoir.pdf_service as pdf_service_module
from app.features.memoir.memoir_images.storage import CosDownloadUrlError
class PDFServiceImagesTest(unittest.IsolatedAsyncioTestCase):
@patch("api.services.pdf_service.ReportLabImage")
@patch("api.services.pdf_service.httpx.AsyncClient")
@patch("api.services.pdf_service.TencentCosStorageService")
@patch("app.features.memoir.pdf_service.ReportLabImage")
@patch("app.features.memoir.pdf_service.httpx.AsyncClient")
@patch("app.features.memoir.pdf_service.TencentCosStorageService")
async def test_generate_pdf_preserves_image_aspect_ratio(
self,
storage_cls,
@@ -60,8 +61,8 @@ class PDFServiceImagesTest(unittest.IsolatedAsyncioTestCase):
self.assertAlmostEqual(kwargs["width"], 5 * 72)
self.assertAlmostEqual(kwargs["height"], 2.5 * 72)
@patch("api.services.pdf_service.httpx.AsyncClient")
@patch("api.services.pdf_service.TencentCosStorageService")
@patch("app.features.memoir.pdf_service.httpx.AsyncClient")
@patch("app.features.memoir.pdf_service.TencentCosStorageService")
async def test_generate_pdf_embeds_completed_images_and_removes_placeholders(
self,
storage_cls,
@@ -110,8 +111,8 @@ class PDFServiceImagesTest(unittest.IsolatedAsyncioTestCase):
self.assertNotIn(b"IMAGE:", pdf_bytes)
mock_client.get.assert_called_once_with("https://signed.example.com/0.png?sig=123")
@patch("api.services.pdf_service.httpx.AsyncClient")
@patch("api.services.pdf_service.TencentCosStorageService")
@patch("app.features.memoir.pdf_service.httpx.AsyncClient")
@patch("app.features.memoir.pdf_service.TencentCosStorageService")
async def test_generate_pdf_skips_private_cos_url_when_signing_fails(
self,
storage_cls,
@@ -121,7 +122,7 @@ class PDFServiceImagesTest(unittest.IsolatedAsyncioTestCase):
async_client_cls.return_value.__aenter__ = AsyncMock(return_value=mock_client)
async_client_cls.return_value.__aexit__ = AsyncMock(return_value=False)
storage = MagicMock()
storage.get_download_url.side_effect = pdf_service_module.CosDownloadUrlError(
storage.get_download_url.side_effect = CosDownloadUrlError(
"cos unavailable", retryable=True, request_id="req-err"
)
storage_cls.from_env.return_value = storage