feat(setup): detect filesystem properties during initial scan

SetupService.run() now checks each anime folder for tvshow.nfo,
logo.png, and poster/fanart images instead of using hardcoded
defaults. Provider key resolution via search is unchanged.
This commit is contained in:
2026-06-05 20:05:04 +02:00
parent 5c2be3f7c4
commit 18d10b44b5
3 changed files with 262 additions and 4 deletions

View File

@@ -390,3 +390,155 @@ class TestSetupServiceRun:
assert result == 1
mock_create.assert_called_once()
class TestCheckNfoFile:
"""Test _check_nfo_file method."""
def test_returns_true_when_tvshow_nfo_exists(self, tmp_path):
"""tvshow.nfo exists → returns (True, path, created, updated)."""
folder = tmp_path / "Series"
folder.mkdir()
nfo_file = folder / "tvshow.nfo"
nfo_file.touch()
has_nfo, nfo_path, created, updated = SetupService._check_nfo_file(folder)
assert has_nfo is True
assert nfo_path == str(nfo_file)
assert created is not None
assert updated is not None
def test_returns_false_when_no_nfo(self, tmp_path):
"""No tvshow.nfo → returns (False, None, None, None)."""
folder = tmp_path / "Series"
folder.mkdir()
has_nfo, nfo_path, created, updated = SetupService._check_nfo_file(folder)
assert has_nfo is False
assert nfo_path is None
assert created is None
assert updated is None
def test_returns_false_when_nfo_is_directory(self, tmp_path):
"""tvshow.nfo exists but is a directory → returns False."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "tvshow.nfo").mkdir()
has_nfo, nfo_path, created, updated = SetupService._check_nfo_file(folder)
assert has_nfo is False
class TestCheckLogoFile:
"""Test _check_logo_file method."""
def test_returns_true_when_logo_png_exists(self, tmp_path):
"""logo.png exists → returns True."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "logo.png").touch()
assert SetupService._check_logo_file(folder) is True
def test_returns_false_when_no_logo(self, tmp_path):
"""No logo.png → returns False."""
folder = tmp_path / "Series"
folder.mkdir()
assert SetupService._check_logo_file(folder) is False
def test_returns_false_for_other_files(self, tmp_path):
"""Files like logo.jpg or logo.gif → returns False."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "logo.jpg").touch()
(folder / "logo.gif").touch()
assert SetupService._check_logo_file(folder) is False
class TestCheckImageFiles:
"""Test _check_image_files method."""
def test_returns_true_for_poster_jpg(self, tmp_path):
"""poster.jpg exists → returns True."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "poster.jpg").touch()
assert SetupService._check_image_files(folder) is True
def test_returns_true_for_poster_jpeg(self, tmp_path):
"""poster.jpeg exists → returns True."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "poster.jpeg").touch()
assert SetupService._check_image_files(folder) is True
def test_returns_true_for_poster_png(self, tmp_path):
"""poster.png exists → returns True."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "poster.png").touch()
assert SetupService._check_image_files(folder) is True
def test_returns_true_for_fanart_jpg(self, tmp_path):
"""fanart.jpg exists → returns True."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "fanart.jpg").touch()
assert SetupService._check_image_files(folder) is True
def test_returns_false_when_no_images(self, tmp_path):
"""No poster or fanart images → returns False."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "episode_01.mp4").touch()
assert SetupService._check_image_files(folder) is False
def test_returns_false_for_unrelated_files(self, tmp_path):
"""Files not matching poster/fanart pattern → returns False."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "banner.png").touch()
(folder / "thumbnail.jpg").touch()
assert SetupService._check_image_files(folder) is False
class TestGetSeriesProperties:
"""Test _get_series_properties method."""
def test_returns_all_properties_from_filesystem(self, tmp_path):
"""Folder with tvshow.nfo, logo.png, poster.jpg → returns correct props."""
folder = tmp_path / "Series"
folder.mkdir()
(folder / "tvshow.nfo").touch()
(folder / "logo.png").touch()
(folder / "poster.jpg").touch()
props = SetupService._get_series_properties(folder)
assert props.has_nfo is True
assert props.nfo_path is not None
assert props.logo_loaded is True
assert props.images_loaded is True
def test_returns_defaults_when_no_files(self, tmp_path):
"""Empty folder → returns all False/None."""
folder = tmp_path / "Series"
folder.mkdir()
props = SetupService._get_series_properties(folder)
assert props.has_nfo is False
assert props.nfo_path is None
assert props.logo_loaded is False
assert props.images_loaded is False