849eb0ff48
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import os
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from app.services.transcription import extract_audio, transcribe_audio
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_extract_audio_calls_ffmpeg():
|
|
with patch("app.services.transcription.subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
result = extract_audio("/tmp/test.mp4")
|
|
assert result.endswith(".wav")
|
|
mock_run.assert_called_once()
|
|
args = mock_run.call_args
|
|
assert "ffmpeg" in args[0][0]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_transcribe_audio_returns_expected_structure():
|
|
mock_segment = MagicMock()
|
|
mock_segment.start = 0.0
|
|
mock_segment.end = 5.0
|
|
mock_segment.text = " Hello world "
|
|
|
|
mock_info = MagicMock()
|
|
mock_info.language = "en"
|
|
|
|
with patch("app.services.transcription._get_model") as mock_model:
|
|
mock_model.return_value.transcribe.return_value = (
|
|
iter([mock_segment]),
|
|
mock_info,
|
|
)
|
|
result = transcribe_audio("/tmp/test.wav")
|
|
|
|
assert "text" in result
|
|
assert result["text"] == "Hello world"
|
|
assert len(result["segments"]) == 1
|
|
assert result["segments"][0]["start"] == 0.0
|
|
assert result["language"] == "en"
|
|
assert "processing_time" in result
|