"""An editor clip is held to its owner's storage cap by its real size, as a download and a player clip are: its file is new storage on the owner's footprint, and nothing else checked it. Real ffmpeg — the size the check reads is the encoder's. """ import shutil import subprocess import pytest from app.config import settings from app.downloads import errors as dlerrors from app.downloads import pipeline, quota, service from app.downloads import upload as uploadmod from app.models import DownloadJob, DownloadQuota, MediaAsset pytestmark = pytest.mark.skipif(shutil.which("ffmpeg") is None, reason="ffmpeg not available") def test_an_editor_clip_larger_than_what_is_left_is_refused_and_not_placed( db, make_user, tmp_path, monkeypatch ): monkeypatch.setattr(settings, "files_root", str(tmp_path)) src = tmp_path / "in.mp4" subprocess.run( [ "ffmpeg", "-y", "-loglevel", "error", "-f", "lavfi", "-i", "testsrc2=size=160x120:rate=10:duration=2", "-c:v", "libx264", "-pix_fmt", "yuv420p", str(src), ], check=True, ) # fmt: skip u = make_user() source = uploadmod.ingest_upload( db, u.id, filename="clip.mp4", src_path=src, size=src.stat().st_size ) job = service.enqueue_edit(db, u.id, source, {"trim": {"start_s": 0, "end_s": 1.5}}) asset = db.get(MediaAsset, job.asset_id) job.status, asset.status = "running", "downloading" # the worker's claim # Ten bytes left: no clip of a real video fits. db.add( DownloadQuota( user_id=u.id, max_bytes=quota.footprint(db, u.id) + 10, max_concurrent=2, max_jobs=100, unlimited=False, ) ) db.commit() pipeline._process_edit(job.id, asset.id) db.expire_all() job, asset = db.get(DownloadJob, job.id), db.get(MediaAsset, job.asset_id) assert (job.status, job.error_code, job.error) == ( "error", "quota_exceeded", dlerrors.CLIP_TOO_BIG_MESSAGE, ) assert asset.rel_path is None assert not list(tmp_path.glob(".edits/**/*.mp4"))