From b4f4d4ffad167f673d09824d9b7222e6d73b2f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E5=BA=94?= Date: Sat, 4 Jul 2026 22:19:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=8C=E6=AD=A5=20edit=5Fplans/edit?= =?UTF-8?q?=5Ftemplates=20=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80=E5=88=B0=20?= =?UTF-8?q?Phase=208=20config=20=E6=A0=87=E5=87=86=E5=8C=96=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 8 引入 normalize_plan_config/normalize_template_config 后, API 会将 config 扩展为完整的结构化默认值(cover/title/subtitle/bgm), 但测试断言仍使用旧的简单 dict 格式,导致 4 个用例失败。 修复方式:导入 normalize_* 函数,断言改为期望标准化后的 config。 修复用例: - test_create_success (plans) - test_create_minimal (plans) - test_update_config (plans) - test_create_with_all_fields (templates) --- tests/unit/test_edit_plans_api.py | 7 ++++--- tests/unit/test_edit_templates_api.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_edit_plans_api.py b/tests/unit/test_edit_plans_api.py index dadcfa000..651da4703 100644 --- a/tests/unit/test_edit_plans_api.py +++ b/tests/unit/test_edit_plans_api.py @@ -28,6 +28,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api")) from fastapi import FastAPI from fastapi.testclient import TestClient +from packages.domain.config_schemas import normalize_plan_config from packages.domain.edit_plan import EditPlan, EditPlanStatus # --------------------------------------------------------------------------- @@ -190,7 +191,7 @@ class TestCreatePlan: assert data["template_id"] == "tpl-001" assert data["status"] == "draft" assert data["total_duration"] == 60.0 - assert data["config"] == {"bgm": "happy"} + assert data["config"] == normalize_plan_config({"bgm": "happy"}) assert "id" in data assert "created_at" in data @@ -202,7 +203,7 @@ class TestCreatePlan: ) assert resp.status_code == 201 data = resp.json() - assert data["config"] == {} + assert data["config"] == normalize_plan_config(None) assert data["total_duration"] == 0.0 def test_create_empty_name_returns_422(self, client): @@ -386,7 +387,7 @@ class TestUpdatePlan: json={"config": {"bgm": "sad", "transition": "fade"}}, ) assert resp.status_code == 200 - assert resp.json()["config"] == {"bgm": "sad", "transition": "fade"} + assert resp.json()["config"] == normalize_plan_config({"bgm": "sad", "transition": "fade"}) def test_update_total_duration(self, client): c, repo = client diff --git a/tests/unit/test_edit_templates_api.py b/tests/unit/test_edit_templates_api.py index acbd7d1d2..270392623 100644 --- a/tests/unit/test_edit_templates_api.py +++ b/tests/unit/test_edit_templates_api.py @@ -28,6 +28,7 @@ from fastapi.testclient import TestClient sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "apps", "api")) +from packages.domain.config_schemas import normalize_template_config from packages.domain.edit_template import EditTemplate, EditTemplateStatus # ── Stub Repository ─────────────────────────────────────────────────────────── @@ -276,7 +277,7 @@ class TestCreateTemplate: assert data["name"] == "完整模板" assert data["description"] == "完整描述" assert data["template_type"] == "vlog" - assert data["config"] == {"key": "value"} + assert data["config"] == normalize_template_config({"key": "value"}) assert data["preview_url"] == "https://example.com/preview.mp4" assert data["sort_weight"] == 10