mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 07:21:28 +00:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from scene_search.paths import resolve_thumb_path
|
|
|
|
|
|
class ThumbnailPathTests(unittest.TestCase):
|
|
def test_existing_path_is_kept(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "frame.jpg"
|
|
path.write_bytes(b"x")
|
|
fake_settings = SimpleNamespace(data_dir=Path(tmp) / "other")
|
|
with patch("scene_search.paths.settings", fake_settings):
|
|
self.assertEqual(resolve_thumb_path(path), path)
|
|
|
|
def test_old_host_thumb_path_rebases_to_current_data_dir(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
data_dir = Path(tmp) / "data"
|
|
target = data_dir / "thumbs" / "media-1" / "frame_000001.jpg"
|
|
target.parent.mkdir(parents=True)
|
|
target.write_bytes(b"x")
|
|
|
|
fake_settings = SimpleNamespace(data_dir=data_dir)
|
|
with patch("scene_search.paths.settings", fake_settings):
|
|
resolved = resolve_thumb_path(
|
|
"/opt/jellyfin-search/data/thumbs/media-1/frame_000001.jpg"
|
|
)
|
|
|
|
self.assertEqual(resolved, target)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|