basyx commited on
Commit
c74baef
·
verified ·
1 Parent(s): e32e185

Test API-wide media output validation

Browse files
Files changed (1) hide show
  1. tests/test_output_validation.py +71 -0
tests/test_output_validation.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import pytest
6
+
7
+ from app.container import build_container
8
+ from app.core.exceptions import ProcessingError
9
+ from app.models.media import OperationResult
10
+
11
+
12
+ @pytest.mark.asyncio
13
+ async def test_output_validation_probes_audio_artifact(settings, tmp_path: Path, monkeypatch) -> None:
14
+ container = build_container(settings)
15
+ output = tmp_path / "final.mp3"
16
+ output.write_bytes(b"audio-placeholder")
17
+
18
+ async def fake_probe(path: Path):
19
+ assert path == output
20
+ return {
21
+ "duration": 12.5,
22
+ "container": "mp3",
23
+ "video_streams": [],
24
+ "audio_streams": [{"codec": "mp3"}],
25
+ "resolution": None,
26
+ }
27
+
28
+ monkeypatch.setattr(container.processor.ffprobe, "probe", fake_probe)
29
+ report = await container.processor.validate_output_result(
30
+ OperationResult(path=output, filename=output.name, mime_type="audio/mpeg")
31
+ )
32
+
33
+ assert report["valid"] is True
34
+ assert report["probed"] is True
35
+ assert report["size_bytes"] == output.stat().st_size
36
+ assert report["audio_stream_count"] == 1
37
+ assert report["duration_seconds"] == 12.5
38
+
39
+
40
+ @pytest.mark.asyncio
41
+ async def test_output_validation_rejects_audio_without_audio_stream(settings, tmp_path: Path, monkeypatch) -> None:
42
+ container = build_container(settings)
43
+ output = tmp_path / "broken.mp3"
44
+ output.write_bytes(b"not-real-audio")
45
+
46
+ async def fake_probe(path: Path):
47
+ return {
48
+ "duration": 1.0,
49
+ "container": "mp3",
50
+ "video_streams": [],
51
+ "audio_streams": [],
52
+ "resolution": None,
53
+ }
54
+
55
+ monkeypatch.setattr(container.processor.ffprobe, "probe", fake_probe)
56
+ with pytest.raises(ProcessingError, match="no audio stream"):
57
+ await container.processor.validate_output_result(
58
+ OperationResult(path=output, filename=output.name, mime_type="audio/mpeg")
59
+ )
60
+
61
+
62
+ @pytest.mark.asyncio
63
+ async def test_output_validation_rejects_empty_artifact(settings, tmp_path: Path) -> None:
64
+ container = build_container(settings)
65
+ output = tmp_path / "empty.mp4"
66
+ output.write_bytes(b"")
67
+
68
+ with pytest.raises(ProcessingError, match="empty"):
69
+ await container.processor.validate_output_result(
70
+ OperationResult(path=output, filename=output.name, mime_type="video/mp4")
71
+ )