videogen/test/services/test_controller_llm.py
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

101 lines
3.2 KiB
Python

import unittest
from unittest.mock import patch
from app.controllers.v1 import llm as llm_controller
from app.models.schema import (
VideoScriptRequest,
VideoSocialMetadataRequest,
VideoTermsRequest,
)
class TestLlmController(unittest.TestCase):
def test_generate_video_script_forwards_all_prompt_fields(self):
"""文案接口不能丢失高级提示词或段落数量。"""
body = VideoScriptRequest(
video_subject="Coffee",
video_language="en",
paragraph_number=2,
video_script_prompt="Friendly tone",
custom_system_prompt="Return narration only.",
)
with patch.object(
llm_controller.llm,
"generate_script",
return_value="Generated script",
) as generate:
response = llm_controller.generate_video_script(None, body)
self.assertEqual(
response,
{"status": 200, "data": {"video_script": "Generated script"}},
)
generate.assert_called_once_with(
video_subject="Coffee",
language="en",
paragraph_number=2,
video_script_prompt="Friendly tone",
custom_system_prompt="Return narration only.",
)
def test_generate_video_terms_forwards_order_matching_mode(self):
"""素材顺序匹配开关必须继续传递到关键词生成服务。"""
body = VideoTermsRequest(
video_subject="Coffee",
video_script="First beans, then brewing.",
amount=4,
match_materials_to_script=True,
)
with patch.object(
llm_controller.llm,
"generate_terms",
return_value=["beans", "brewing"],
) as generate:
response = llm_controller.generate_video_terms(None, body)
self.assertEqual(
response,
{"status": 200, "data": {"video_terms": ["beans", "brewing"]}},
)
generate.assert_called_once_with(
video_subject="Coffee",
video_script="First beans, then brewing.",
amount=4,
match_script_order=True,
)
def test_generate_social_metadata_returns_service_payload(self):
"""社交平台元数据接口应保持服务层结果的响应结构。"""
body = VideoSocialMetadataRequest(
video_subject="Coffee",
video_script="Morning coffee.",
language="en",
platform="youtube_shorts",
)
metadata = {
"title": "Morning Coffee",
"caption": "Start the day.",
"hashtags": ["#coffee"],
}
with patch.object(
llm_controller.llm,
"generate_social_metadata",
return_value=metadata,
) as generate:
response = llm_controller.generate_video_social_metadata(None, body)
self.assertEqual(response, {"status": 200, "data": metadata})
generate.assert_called_once_with(
video_subject="Coffee",
video_script="Morning coffee.",
language="en",
platform="youtube_shorts",
)
if __name__ == "__main__":
unittest.main()