feat(product-suite): make image pulls cancellable

This commit is contained in:
chengma
2026-07-16 19:37:22 +08:00
parent c9afaad24b
commit 75af87d441
12 changed files with 1157 additions and 88 deletions
+33 -2
View File
@@ -7,7 +7,7 @@ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from _helpers import REPO_ROOT # noqa: F401
from app import workers
from app import image_studio_images, workers
if workers.QT_IMPORT_ERROR is not None:
raise unittest.SkipTest("PySide6 未安装")
@@ -16,7 +16,10 @@ from PySide6.QtCore import QEventLoop, QTimer
from PySide6.QtWidgets import QApplication
from app.workers import BaseWorker, run_worker
from app.gui.workers import ImageStudioDownloadOriginalWorker
from app.gui.workers import (
ImageStudioDownloadOriginalWorker,
ImageStudioPullImagesWorker,
)
class DemoWorker(BaseWorker):
@@ -165,6 +168,34 @@ class WorkerTests(unittest.TestCase):
self.assertEqual("蝦皮原主图下载失败,请稍后再次点击图片重试。", summary["error"])
self.assertNotIn("https://", summary["error"])
def test_image_studio_pull_worker_returns_token_when_cancelled(self):
worker = ImageStudioPullImagesWorker(
"alias-a",
"51100639510",
pull_run_token="pull-token",
)
worker.cancel()
with mock.patch(
"app.gui.workers.image_studio.pull_remote_main_image_urls",
) as pull:
summary = worker.execute()
pull.assert_not_called()
self.assertTrue(summary["cancelled"])
self.assertEqual("pull-token", summary["pull_run_token"])
def test_image_studio_original_download_maps_safe_cancel(self):
worker = ImageStudioDownloadOriginalWorker(12)
with mock.patch(
"app.gui.workers.image_studio_images.download_original_asset",
side_effect=image_studio_images.ImageStudioImageCancelled("停止"),
):
summary = worker.execute()
self.assertEqual({"asset_id": 12, "cancelled": True}, summary)
if __name__ == "__main__":
unittest.main()