Add media retention cleanup command
All checks were successful
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
buildbot/nix-effects Build done.

This commit is contained in:
Abel Luck 2026-05-27 13:04:47 +02:00
parent 3b6503a6ed
commit 507074b80e
10 changed files with 722 additions and 52 deletions

View file

@ -39,6 +39,102 @@ def test_parse_args_supports_dev_mode_flag() -> None:
assert args.dev_mode is True
def test_parse_args_supports_cleanup_media_defaults() -> None:
command, args = parse_args(["cleanup-media"])
assert command == "cleanup-media"
assert args.config is None
assert args.feeds_dir is None
assert args.days == 25
assert args.dry_run is False
def test_entrypoint_runs_cleanup_media(monkeypatch, tmp_path) -> None:
recorded: dict[str, object] = {}
class FakeResult:
failures = 0
def fake_cleanup_media(*, feeds_dir, retention_days, dry_run, media_dirs):
recorded["feeds_dir"] = feeds_dir
recorded["retention_days"] = retention_days
recorded["dry_run"] = dry_run
recorded["media_dirs"] = media_dirs
return FakeResult()
monkeypatch.setattr("repub.entrypoint.cleanup_media", fake_cleanup_media)
exit_code = entrypoint(
[
"cleanup-media",
"--feeds-dir",
str(tmp_path / "feeds"),
"--days",
"10",
"--dry-run",
]
)
assert exit_code == 0
assert recorded == {
"feeds_dir": tmp_path / "feeds",
"retention_days": 10,
"dry_run": True,
"media_dirs": ("images", "audio", "video", "files"),
}
def test_entrypoint_cleanup_media_uses_configured_media_dirs(
monkeypatch, tmp_path
) -> None:
config_path = tmp_path / "repub.toml"
config_path.write_text(
"""
out_dir = "mirror"
[[feeds]]
name = "Demo"
slug = "demo"
url = "https://source.example/feed.rss"
[scrapy.settings]
REPUBLISHER_IMAGE_DIR = "images-custom"
REPUBLISHER_AUDIO_DIR = "audio-custom"
REPUBLISHER_VIDEO_DIR = "videos-custom"
REPUBLISHER_FILE_DIR = "files-custom"
""".strip(),
encoding="utf-8",
)
recorded: dict[str, object] = {}
class FakeResult:
failures = 0
def fake_cleanup_media(*, feeds_dir, retention_days, dry_run, media_dirs):
recorded["feeds_dir"] = feeds_dir
recorded["retention_days"] = retention_days
recorded["dry_run"] = dry_run
recorded["media_dirs"] = media_dirs
return FakeResult()
monkeypatch.setattr("repub.entrypoint.cleanup_media", fake_cleanup_media)
exit_code = entrypoint(["cleanup-media", "--config", str(config_path)])
assert exit_code == 0
assert recorded == {
"feeds_dir": tmp_path / "mirror" / "feeds",
"retention_days": 25,
"dry_run": False,
"media_dirs": (
"images-custom",
"audio-custom",
"videos-custom",
"files-custom",
),
}
def test_parse_args_defaults_to_dev_mode_when_no_args() -> None:
command, args = parse_args([])