# -*- coding: utf-8 -*- from __future__ import annotations from pathlib import Path def test_delete_channel_cascades_jobs_and_clips(temp_db, tmp_path): ch = temp_db.create_shorts_channel(name="gone", enabled=True) clip = tmp_path / "a.mp4" clip.write_bytes(b"fake") job = temp_db.create_shorts_job(session_id="", room_id="r1", channel_pk=ch["id"]) temp_db.update_shorts_job(job["id"], status="scheduled", clip_path=str(clip), upload_at=1) stats = temp_db.delete_shorts_channel(ch["id"]) assert stats["channel"] == 1 assert stats["jobs"] == 1 assert stats["clips"] == 1 assert temp_db.get_shorts_channel(ch["id"]) is None assert temp_db.get_shorts_job(job["id"]) is None assert not clip.exists() def test_purge_orphan_shorts_jobs(temp_db, tmp_path): clip = tmp_path / "orphan.mp4" clip.write_bytes(b"x") job = temp_db.create_shorts_job(session_id="", room_id="r2", channel_pk="missing-channel-id") temp_db.update_shorts_job(job["id"], status="recorded", clip_path=str(clip)) stats = temp_db.purge_orphan_shorts_jobs() assert stats["jobs"] == 1 assert stats["clips"] == 1 assert temp_db.get_shorts_job(job["id"]) is None assert not clip.exists()