From b7401fcffab3586414bb323ceab154d1f8645656 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Mon, 31 Aug 2026 10:02:51 +0000 Subject: [PATCH] style: auto-format with black + isort + prettier [skip ci-format-check] --- ...grate_template_segments_to_clip_configs.py | 15 +++----- tests/unit/test_unify_template_segments.py | 34 +++++++------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/alembic/versions/060_migrate_template_segments_to_clip_configs.py b/alembic/versions/060_migrate_template_segments_to_clip_configs.py index 9805c3075..bb245b05d 100644 --- a/alembic/versions/060_migrate_template_segments_to_clip_configs.py +++ b/alembic/versions/060_migrate_template_segments_to_clip_configs.py @@ -12,6 +12,7 @@ import json import uuid import sqlalchemy as sa + from alembic import op revision = "060_migrate_segments" @@ -29,24 +30,19 @@ def upgrade() -> None: conn = op.get_bind() # 找出有旧数据但没有新数据的 template_id - rows = conn.execute( - sa.text( - """ + rows = conn.execute(sa.text(""" SELECT ts.id, ts.template_id, ts.segment_order, ts.duration_min, ts.duration_max, ts.material_type FROM template_segments ts WHERE ts.template_id NOT IN ( SELECT DISTINCT tcc.template_id FROM template_clip_configs tcc ) ORDER BY ts.template_id, ts.segment_order - """ - ) - ) + """)) for row in rows: config = {"material_type": row[5]} if row[5] else {} conn.execute( - sa.text( - """ + sa.text(""" INSERT INTO template_clip_configs (id, template_id, clip_type, "order", min_duration, max_duration, text_template, material_requirements, transition_effect, config, @@ -54,8 +50,7 @@ def upgrade() -> None: VALUES (:id, :template_id, 'main', :seg_order, :dur_min, :dur_max, '', '{}', 'cut', :config, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - """ - ), + """), { "id": uuid.uuid4().hex, "template_id": row[1], diff --git a/tests/unit/test_unify_template_segments.py b/tests/unit/test_unify_template_segments.py index 9a73e703e..ed4db7ac9 100644 --- a/tests/unit/test_unify_template_segments.py +++ b/tests/unit/test_unify_template_segments.py @@ -57,9 +57,7 @@ class TestCreateSegmentsWritesToClipConfigs: repo.create_segments([seg]) # 验证 template_clip_configs 有记录 - clips = db_session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).all() + clips = db_session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).all() assert len(clips) == 1 assert clips[0].order == 0 assert clips[0].min_duration == 3.0 @@ -74,9 +72,7 @@ class TestCreateSegmentsWritesToClipConfigs: seg = _make_segment(tpl.id, 0) repo.create_segments([seg]) - old_rows = db_session.query(TemplateSegmentModel).filter( - TemplateSegmentModel.template_id == tpl.id - ).all() + old_rows = db_session.query(TemplateSegmentModel).filter(TemplateSegmentModel.template_id == tpl.id).all() assert len(old_rows) == 0 @@ -183,9 +179,7 @@ class TestDeleteSegments: count = repo.delete_segments_by_template(tpl.id) assert count == 1 - clips = db_session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).all() + clips = db_session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).all() assert len(clips) == 0 def test_delete_template_clears_both_tables(self, repo: SQLAlchemyTemplateRepository, db_session: Session): @@ -206,14 +200,10 @@ class TestDeleteSegments: repo.delete(tpl.id, "user1") - clips = db_session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).all() + clips = db_session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).all() assert len(clips) == 0 - old_rows = db_session.query(TemplateSegmentModel).filter( - TemplateSegmentModel.template_id == tpl.id - ).all() + old_rows = db_session.query(TemplateSegmentModel).filter(TemplateSegmentModel.template_id == tpl.id).all() assert len(old_rows) == 0 @@ -223,10 +213,12 @@ class TestCopyTemplateSegments: def test_copy_preserves_segments(self, repo: SQLAlchemyTemplateRepository, db_session: Session): tpl = _make_template() repo.create(tpl) - repo.create_segments([ - _make_segment(tpl.id, 0, "video"), - _make_segment(tpl.id, 1, "voiceover"), - ]) + repo.create_segments( + [ + _make_segment(tpl.id, 0, "video"), + _make_segment(tpl.id, 1, "voiceover"), + ] + ) copied = repo.copy_template(tpl.id, "user1", "copy") assert len(copied.segments) == 2 @@ -234,9 +226,7 @@ class TestCopyTemplateSegments: assert copied.segments[1].material_type == "voiceover" # 验证新模板的 clip_configs 有数据 - clips = db_session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == copied.id - ).all() + clips = db_session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == copied.id).all() assert len(clips) == 2