cmvr-visual/backend/tests/test_caption_birth.py

68 lines
2.6 KiB
Python

import pytest
from test_dialogue_engine import story
from test_caption_rhythm import STYLE, case
@pytest.mark.parametrize(
"choice,expected",
[
({}, None),
({"captions_mode": "none"}, None),
({"captions_mode": "manual"}, None),
({"captions_mode": "script"}, STYLE),
(
{
"captions_mode": "script",
"caption_presentation": {"punctuation": "preserve", "pacing": "sentence"},
},
{"punctuation": "preserve", "pacing": "sentence"},
),
],
)
async def test_create_intent_is_consumed_on_later_dialogue_enable(system, choice, expected):
c = system.client
created = await c.post("/api/stories", json={"spec": story(), "name": "新故事", **choice})
assert created.status_code == 201, created.text
did = created.json()["id"]
assert created.json()["editor_manifest"] is None
url = f"/api/editors/{did}/dialogue/enable"
enabled = await c.post(
url, json={"expected_version": 1}, headers={"Idempotency-Key": "enable-new"}
)
assert enabled.status_code == 200, enabled.text
m = enabled.json()["manifest"]
assert m["captions"].get("presentation") == expected
assert m["schema_version"] == (4 if expected else 3)
assert m["captions"]["mode"] == choice.get("captions_mode", "none")
assert (await c.get(f"/api/editors/{did}")).json()["manifest"] == m
async def test_explicitly_auto_captioned_native_story_has_default_at_birth(system):
m, _, _ = case()
resp = await system.client.post(
"/api/stories", json={"name": "新建原生对白", "spec": m["spec"], "captions_mode": "script"}
)
assert resp.status_code == 201, resp.text
assert resp.json()["editor_manifest"]["captions"]["presentation"] == STYLE
async def test_new_non_chinese_native_story_keeps_sentence_rendering(system):
m, _, _ = case()
m["spec"]["dialogue"]["language"] = "English"
resp = await system.client.post(
"/api/stories", json={"name": "English", "spec": m["spec"], "captions_mode": "script"}
)
assert resp.status_code == 201, resp.text
editor = resp.json()["editor_manifest"]
assert editor["schema_version"] == 3
assert editor["captions"] == dict(mode="script", cues=[])
async def test_new_native_story_without_automatic_captions_has_no_style(system):
m, _, _ = case()
resp = await system.client.post("/api/stories", json={"name": "无自动字幕", "spec": m["spec"]})
assert resp.status_code == 201, resp.text
editor = (await system.client.get("/api/editors/" + resp.json()["id"])).json()["manifest"]
assert editor["captions"] == dict(mode="none", cues=[])