Files
SakuraHub/tests/test_cloud_upload_removed.py
2026-11-16 20:45:22 +08:00

66 lines
2.6 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from pixiv_app.core.plugin.base import Resource
from pixiv_app.core.x_media_service import XMediaService
PROJECT_ROOT = Path(__file__).resolve().parents[1]
class _LocalOnlyPlugin:
def download(self, resource: Resource, save_root: Path) -> list[Path]:
save_root.mkdir(parents=True, exist_ok=True)
target = save_root / f"{resource.id}.jpg"
target.write_bytes(b"local-only")
return [target]
class CloudUploadRemovedTests(unittest.TestCase):
def test_desktop_download_entrypoints_do_not_call_cloud_upload(self) -> None:
callers = (
PROJECT_ROOT / "pixiv_app" / "gui" / "app.py",
PROJECT_ROOT / "pixiv_app" / "services" / "gallery_api.py",
PROJECT_ROOT / "pixiv_app" / "core" / "x_media_service.py",
PROJECT_ROOT / "pixiv_app" / "core" / "gallery_service.py",
PROJECT_ROOT / "pixiv_app" / "core" / "origin_follow_sync.py",
)
for path in callers:
source = path.read_text(encoding="utf-8")
self.assertNotIn(".sync_file(", source, path.name)
self.assertNotIn("sync_plugin_paths(", source, path.name)
self.assertNotIn("sync_pixiv_result(", source, path.name)
self.assertNotIn("SakuraCloudClient(", source, path.name)
self.assertNotIn(".upsert_follow(", source, path.name)
self.assertNotIn(".create_alert(", source, path.name)
self.assertNotIn(".bulk_upsert_follows(", source, path.name)
def test_x_preview_download_is_local_only(self) -> None:
with tempfile.TemporaryDirectory() as directory:
service = XMediaService(save_root=Path(directory))
service._manager = type("Manager", (), {"plugins": {"X": _LocalOnlyPlugin()}})()
service._preview_cache["preview"] = [
Resource(
id="tweet-1",
url="https://x.com/example/status/1",
title="example",
author="Example",
author_id="example",
files=[{"type": "image", "url": "https://example.invalid/image.jpg"}],
)
]
result = service.download_preview("preview")
self.assertEqual(result["downloaded_files"], 1)
self.assertEqual(result["synced_files"], 0)
self.assertEqual(result["items"][0]["synced_files"], 0)
self.assertTrue(Path(result["items"][0]["paths"][0]).is_file())
if __name__ == "__main__":
unittest.main()