add a retranslate chinese function
This commit is contained in:
@@ -391,6 +391,59 @@ def test_subtitle_translation_does_not_block_http_on_long_jobs(tmp_path, monkeyp
|
||||
assert len(requested) == 1
|
||||
|
||||
|
||||
def test_admin_can_retranslate_subtitles_with_name_terms(tmp_path, monkeypatch):
|
||||
client = make_client(tmp_path)
|
||||
_ready_video(client.app.state.video_repository)
|
||||
requested = []
|
||||
|
||||
def translate_sentences(sentences, **kwargs):
|
||||
requested.append((sentences, kwargs.get("terms")))
|
||||
terms = dict(kwargs.get("terms") or [])
|
||||
return {
|
||||
index: terms.get("Harimoto", "哈达马托") + f":{text}"
|
||||
for index, text in sentences
|
||||
}
|
||||
|
||||
class StubAITutor:
|
||||
available = True
|
||||
|
||||
stub = StubAITutor()
|
||||
stub.translate_sentences = translate_sentences
|
||||
monkeypatch.setattr(client.app.state, "ai_tutor", stub)
|
||||
client.app.state.subtitle_translations.ai_tutor = stub
|
||||
client.app.state.subtitle_translations.post_wait_seconds = 0.2
|
||||
|
||||
first = client.post(f"/api/v1/videos/{VIDEO_HASH}/subtitle-translation")
|
||||
if not first.json().get("complete"):
|
||||
first = wait_for_subtitle_translation(client, VIDEO_HASH)
|
||||
assert first.json()["translations"] == [
|
||||
{"index": 0, "zh_text": "哈达马托:Hello."},
|
||||
{"index": 1, "zh_text": "哈达马托:Nice to meet you."},
|
||||
]
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/admin/videos/{VIDEO_HASH}/subtitle-translation",
|
||||
json={"terms": [{"source": "Harimoto", "zh": "哈瑞么托"}]},
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
if not response.json().get("complete"):
|
||||
response = wait_for_subtitle_translation(client, VIDEO_HASH)
|
||||
stored = client.get(f"/api/v1/admin/videos/{VIDEO_HASH}/subtitle-translation")
|
||||
assert stored.status_code == 200
|
||||
payload = stored.json()
|
||||
else:
|
||||
payload = response.json()
|
||||
assert payload["translations"] == [
|
||||
{"index": 0, "zh_text": "哈瑞么托:Hello."},
|
||||
{"index": 1, "zh_text": "哈瑞么托:Nice to meet you."},
|
||||
]
|
||||
assert payload["terms"] == [{"source": "Harimoto", "zh": "哈瑞么托"}]
|
||||
assert requested[-1][1] == [("Harimoto", "哈瑞么托")]
|
||||
assert client.app.state.video_repository.get_translation_glossary(VIDEO_HASH) == [
|
||||
("Harimoto", "哈瑞么托")
|
||||
]
|
||||
|
||||
|
||||
def test_oss_video_url_is_used_for_catalog_and_content(tmp_path):
|
||||
index_path = tmp_path / "boundaries.json"
|
||||
index_path.write_text("{}", encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user