git commit -m "feat: major architectural refactor
- Refactor memory system (episodic/STM/LTM with components) - Implement complete subtitle domain (scanner, matcher, placer) - Add YAML workflow infrastructure - Externalize knowledge base (patterns, release groups) - Add comprehensive testing suite - Create manual testing CLIs"
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
"""
|
||||
Tests for alfred.application.filesystem.create_seed_links.CreateSeedLinksUseCase
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from alfred.application.filesystem.create_seed_links import CreateSeedLinksUseCase
|
||||
from alfred.infrastructure.filesystem.file_manager import FileManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fm():
|
||||
return FileManager()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def use_case(fm):
|
||||
return CreateSeedLinksUseCase(fm)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def seed_env(tmp_path_factory):
|
||||
"""
|
||||
Realistic post-move environment (uses its own tmp dir, independent of app_temp):
|
||||
- library video file (hard-linked from original)
|
||||
- original download folder with remaining files
|
||||
- torrents root folder
|
||||
"""
|
||||
d = tmp_path_factory.mktemp("seed_env")
|
||||
|
||||
lib_dir = d / "tv" / "Oz.1997.1080p.WEBRip.x265-KONTRAST" / "Oz.S01.1080p.WEBRip.x265-KONTRAST"
|
||||
lib_dir.mkdir(parents=True)
|
||||
lib_video = lib_dir / "Oz.S01E01.1080p.WEBRip.x265-KONTRAST.mp4"
|
||||
lib_video.write_bytes(b"video")
|
||||
|
||||
dl = d / "downloads" / "Oz.S01.1080p.WEBRip.x265-KONTRAST"
|
||||
dl.mkdir(parents=True)
|
||||
(dl / "KONTRAST.txt").write_text("release notes")
|
||||
(dl / "[TGx]info.txt").write_text("tgx")
|
||||
subs = dl / "Subs" / "Oz.S01E01.1080p.WEBRip.x265-KONTRAST"
|
||||
subs.mkdir(parents=True)
|
||||
(subs / "2_eng,English [CC][SDH].srt").write_text("1\n00:00:01 --> 00:00:02\nHello\n")
|
||||
|
||||
torrents = d / "torrents"
|
||||
torrents.mkdir()
|
||||
|
||||
return lib_video, dl, torrents
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Happy path
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestCreateSeedLinksHappyPath:
|
||||
|
||||
def test_ok_when_torrent_folder_configured(self, use_case, seed_env, memory_configured):
|
||||
from alfred.infrastructure.persistence import get_memory
|
||||
mem = get_memory()
|
||||
lib_video, dl, torrents = seed_env
|
||||
mem.ltm.workspace.torrent = str(torrents)
|
||||
mem.save()
|
||||
|
||||
result = use_case.execute(str(lib_video), str(dl))
|
||||
|
||||
assert result.status == "ok"
|
||||
assert result.torrent_subfolder is not None
|
||||
assert result.linked_file is not None
|
||||
assert result.copied_count > 0
|
||||
|
||||
def test_to_dict_ok(self, use_case, seed_env, memory_configured):
|
||||
from alfred.infrastructure.persistence import get_memory
|
||||
mem = get_memory()
|
||||
lib_video, dl, torrents = seed_env
|
||||
mem.ltm.workspace.torrent = str(torrents)
|
||||
mem.save()
|
||||
|
||||
d = use_case.execute(str(lib_video), str(dl)).to_dict()
|
||||
assert d["status"] == "ok"
|
||||
assert "torrent_subfolder" in d
|
||||
assert "copied_files" in d
|
||||
assert isinstance(d["copied_files"], list)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Error: torrent folder not configured
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestCreateSeedLinksErrors:
|
||||
|
||||
def test_error_when_torrent_not_configured(self, use_case, seed_env, memory):
|
||||
lib_video, dl, _ = seed_env
|
||||
result = use_case.execute(str(lib_video), str(dl))
|
||||
|
||||
assert result.status == "error"
|
||||
assert result.error == "torrent_folder_not_set"
|
||||
assert result.message is not None
|
||||
|
||||
def test_to_dict_error(self, use_case, seed_env, memory):
|
||||
lib_video, dl, _ = seed_env
|
||||
d = use_case.execute(str(lib_video), str(dl)).to_dict()
|
||||
assert d["status"] == "error"
|
||||
assert "error" in d
|
||||
assert "message" in d
|
||||
|
||||
def test_error_delegates_to_file_manager(self, memory_configured):
|
||||
"""FileManager errors are propagated correctly."""
|
||||
from alfred.infrastructure.persistence import get_memory
|
||||
mem = get_memory()
|
||||
# torrent already configured by memory_configured fixture
|
||||
# library_file does not exist → should propagate error from FileManager
|
||||
uc = CreateSeedLinksUseCase(FileManager())
|
||||
result = uc.execute("/nonexistent/lib.mkv", "/nonexistent/dl")
|
||||
assert result.status == "error"
|
||||
Reference in New Issue
Block a user