cmvr-visual/backend/tests/test_story_film_preview.py

68 lines
2.5 KiB
Python

"""成片预览使用当前故事的最终输出,不依赖运行历史分页或当前编辑模式。"""
from datetime import timedelta
from sqlalchemy import select
from app.models import Asset, User, WorkflowRun, utcnow
async def test_story_film_preview_reads_only_latest_playable_final_output(system, other_client):
c = system.client
story = (
await c.post(
"/api/stories",
json={"name": "Film", "spec": {"shots": [{"id": "1" * 32, "visual_prompt": "一盏灯"}]}},
)
).json()
path = "/api/stories/" + story["id"] + "/film"
blank = await c.get(path)
assert blank.status_code == 200, blank.text
assert blank.json() is None
assert (await other_client.get(path)).status_code == 404
async with system.app.state.db.session() as s:
owner = await s.scalar(select(User.id).where(User.username == "admin"))
foreign = await s.scalar(select(User.id).where(User.username == "alice"))
now = utcnow()
for i, (draft_id, state, goal, asset_owner, deleted) in enumerate(
[
(story["id"], "succeeded", "film", owner, False),
(story["id"], "succeeded", "film", owner, False),
("other", "succeeded", "film", owner, False),
(story["id"], "succeeded", "film", foreign, False),
(story["id"], "succeeded", "film", owner, True),
(story["id"], "succeeded", "media", owner, False),
(story["id"], "running", "film", owner, False),
]
):
asset = Asset(
owner_id=asset_owner,
name=f"{i}.mp4",
kind="video",
mime_type="video/mp4",
storage_key=f"{i}.mp4",
sha256=f"{i:064x}",
size_bytes=1,
deleted_at=now if deleted else None,
)
s.add(asset)
await s.flush()
s.add(
WorkflowRun(
owner_id=owner,
draft_id=draft_id,
draft_revision=i,
spec_snapshot={},
spec_hash="0" * 64,
state=state,
output_goal=goal,
current_output_asset_id=asset.id,
created_at=now + timedelta(seconds=i),
)
)
await s.commit()
result = await c.get(path)
assert result.status_code == 200
assert result.json()["asset"]["name"] == "1.mp4"
assert result.json()["draft_revision"] == 1