astrbot_plugin_imagestudio/tests/test_chat_media_import_service.py

22 行
804 B
Python

import base64
from pathlib import Path
from backend.services.chat_media_import_service import ChatMediaImportService
class Storage:
def __init__(self, root): self.root = Path(root)
def resolve_uri(self, uri): return self.root / uri.removeprefix("storage://materials/")
def ensure_file(self, uri):
path = self.resolve_uri(uri)
if not path.is_file(): raise FileNotFoundError(uri)
return path
def test_data_url_import_uses_portable_storage_path(tmp_path):
service = ChatMediaImportService(Storage(tmp_path))
uri, filename, size = service.import_image("data:image/png;base64," + base64.b64encode(b"png-data").decode())
assert uri.startswith("storage://materials/chat/")
assert "\\" not in uri
assert filename.endswith(".png")
assert size == 8