fixed again

This commit is contained in:
2026-09-05 13:25:12 +08:00
parent 6d9f9a5468
commit 7d843e8ff1
3 changed files with 68 additions and 156 deletions

View File

@@ -1,7 +1,6 @@
import io
import json
from pathlib import Path
import subprocess
from unittest import mock
import wave
from dataclasses import replace
@@ -161,52 +160,27 @@ def test_get_dub_share_includes_video_hash(tmp_path):
assert response.json()["video_hash"] == VIDEO_HASH
def test_create_dub_share_aligns_audio_with_whisper_boundaries(tmp_path):
from sentence_api.transcription import Transcript, TranscriptionSegment
from types import SimpleNamespace
aligned = tmp_path / "aligned.wav"
aligned.write_bytes(b"aligned")
calls = []
class AlignedFakeTranscriber(FakeTranscriber):
available = True
def transcribe(self, audio_path, language=None):
calls.append(audio_path)
return Transcript(
text="The meeting starts at nine.",
segments=[
TranscriptionSegment(
start_seconds=0.4,
end_seconds=1.6,
text="The meeting starts at nine.",
)
],
)
client = make_client(tmp_path, transcriber=AlignedFakeTranscriber())
original_run = subprocess.run
def fake_run(command, **kwargs):
Path(command[-1]).write_bytes(b"aligned-audio")
return SimpleNamespace(returncode=0)
with mock.patch("sentence_api.main.subprocess.run", side_effect=fake_run), mock.patch(
"sentence_api.main._media_duration_seconds",
return_value=2.0,
):
response = client.post(
"/api/v1/dub-shares",
data={
"video_hash": VIDEO_HASH,
"segments": json.dumps([{"sentence_index": 0}]),
},
files={"files": ("dub.wav", make_wav(), "audio/wav")},
)
def test_create_dub_share_keeps_original_audio_without_alignment(tmp_path):
"""Share audio should be stored as uploaded, without tempo/align processing."""
client = make_client(tmp_path)
payload = make_wav()
response = client.post(
"/api/v1/dub-shares",
data={
"video_hash": VIDEO_HASH,
"segments": json.dumps([{"sentence_index": 0}]),
},
files={"files": ("dub.wav", payload, "audio/wav")},
)
assert response.status_code == 201, response.text
assert calls[0].read_bytes() == b"aligned-audio"
share_id = response.json()["share_id"]
detail = client.get(f"/api/v1/dub-shares/{share_id}")
assert detail.status_code == 200
audio_url = detail.json()["segments"][0]["audio_url"]
audio = client.get(audio_url)
assert audio.status_code == 200
assert audio.content == payload
def test_assessment_requires_a_valid_user_session(tmp_path):