From 42c4f22b21669908d9ed27c2399098ffbb71fa02 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Thu, 27 Aug 2026 14:55:51 +0000 Subject: [PATCH] style: auto-format with black + isort + prettier [skip ci-format-check] --- .../app/api/routes/templates_editor/clips.py | 6 ++-- tests/unit/test_mediakit_smart_clips.py | 28 +++++-------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/apps/api/app/api/routes/templates_editor/clips.py b/apps/api/app/api/routes/templates_editor/clips.py index a60598b95..e35c4b03c 100755 --- a/apps/api/app/api/routes/templates_editor/clips.py +++ b/apps/api/app/api/routes/templates_editor/clips.py @@ -17,23 +17,21 @@ from __future__ import annotations import json import logging +import random import re from app.auth import AuthenticatedUser, get_current_user from app.core.storage import get_storage_service -import random - from app.dependencies import get_asset_repository, get_db_session from app.services.edit_plan_service import EditPlanService from app.services.edit_template_service import EditTemplateService from fastapi import APIRouter, Depends, HTTPException, Query, status from sqlalchemy.orm import Session +from packages.adapters.sqlalchemy_impl.asset_repository import SQLAlchemyAssetRepository from packages.adapters.sqlalchemy_impl.template_repository import ( SQLAlchemyTemplateRepository, ) - -from packages.adapters.sqlalchemy_impl.asset_repository import SQLAlchemyAssetRepository from packages.domain.plan_generator_utils import _calc_random_start_time from packages.shared.mediakit_client import get_mediakit_client diff --git a/tests/unit/test_mediakit_smart_clips.py b/tests/unit/test_mediakit_smart_clips.py index dc0bfd2a0..f3116bb25 100644 --- a/tests/unit/test_mediakit_smart_clips.py +++ b/tests/unit/test_mediakit_smart_clips.py @@ -26,7 +26,6 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "apps" / "api")) import pytest - # ── _recommended_time_conflicts 单元测试 ───────────────────────────────────── @@ -248,9 +247,7 @@ class TestGetTemplateSegments: mock_tpl_svc = MagicMock() mock_tpl_svc.list_clip_configs.return_value = [] - with patch( - "app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository" - ) as MockRepo: + with patch("app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository") as MockRepo: mock_repo = MagicMock() seg1 = MagicMock() seg1.segment_order = 0 @@ -270,9 +267,7 @@ class TestGetTemplateSegments: mock_tpl_svc = MagicMock() mock_tpl_svc.list_clip_configs.return_value = [] - with patch( - "app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository" - ) as MockRepo: + with patch("app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository") as MockRepo: mock_repo = MagicMock() mock_repo.list_segments.return_value = [] MockRepo.return_value = mock_repo @@ -287,9 +282,7 @@ class TestGetTemplateSegments: mock_tpl_svc = MagicMock() mock_tpl_svc.list_clip_configs.side_effect = RuntimeError("db error") - with patch( - "app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository" - ) as MockRepo: + with patch("app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository") as MockRepo: mock_repo = MagicMock() seg = MagicMock() seg.segment_order = 0 @@ -393,9 +386,7 @@ class TestFromAssetsByTemplateSegments: mock_asset_repo.get.return_value = _make_rich_asset("a1", 60.0) # 传了 required_clips_count=2,但应该创建4个片段 - body = ClipsFromAssetsRequest( - asset_ids=["a1"], required_clips_count=2 - ) + body = ClipsFromAssetsRequest(asset_ids=["a1"], required_clips_count=2) result = create_clips_from_assets_editor( template_id="tmpl-1", body=body, @@ -523,18 +514,15 @@ class TestFromAssetsByTemplateSegments: def test_no_segments_raises_400(self): """模板没有 segment 配置时返回 400。""" - from fastapi import HTTPException - from app.api.routes.templates_editor.clips import create_clips_from_assets_editor from app.api.routes.templates_editor.schemas import ClipsFromAssetsRequest + from fastapi import HTTPException mock_tpl_svc = MagicMock() mock_tpl_svc.list_clip_configs.return_value = [] mock_plan_svc = _make_plan_svc() - with patch( - "app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository" - ) as MockRepo: + with patch("app.api.routes.templates_editor.clips.SQLAlchemyTemplateRepository") as MockRepo: mock_repo = MagicMock() mock_repo.list_segments.return_value = [] MockRepo.return_value = mock_repo @@ -606,9 +594,7 @@ class TestFromAssetsByTemplateSegments: @patch("app.api.routes.templates_editor.clips.get_mediakit_client") @patch("app.api.routes.templates_editor.clips.get_storage_service") - def test_mediakit_first_clip_uses_recommendation( - self, mock_storage, mock_client_fn - ): + def test_mediakit_first_clip_uses_recommendation(self, mock_storage, mock_client_fn): """MediaKit 推荐时间用于每个素材的第一个片段。""" from app.api.routes.templates_editor.clips import create_clips_from_assets_editor from app.api.routes.templates_editor.schemas import ClipsFromAssetsRequest