File size: 6,463 Bytes
c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa 2e6074b 7af5aaa 2e6074b 7af5aaa 2e6074b c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e 7af5aaa c63c39e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | import json
import os
import sys
import time
from fastapi.testclient import TestClient
# Setup path
current_dir = os.path.dirname(os.path.abspath(__file__))
clipping_dir = os.path.dirname(current_dir)
if clipping_dir not in sys.path:
sys.path.append(clipping_dir)
from main import app
from routers.video import ORIGINALS_DIR, TEMP_DIR, PROCESSED_DIR
client = TestClient(app)
def create_mock_video_if_needed(filename="0eb30aa9_original_my_movie.mp4"):
path = os.path.join(ORIGINALS_DIR, filename)
if not os.path.exists(path):
print(f"Creating mock video at {path}...")
import imageio_ffmpeg
import subprocess
exe = imageio_ffmpeg.get_ffmpeg_exe()
subprocess.run([
exe, '-f', 'lavfi', '-i', 'testsrc=duration=5:size=640x360:rate=30',
'-f', 'lavfi', '-i', 'sine=frequency=1000:duration=5',
'-c:v', 'libx264', '-t', '5', path, '-y'
], capture_output=True)
return filename
def create_mock_audio():
audio_filename = "test_bg_music.mp3"
path = os.path.join(TEMP_DIR, audio_filename)
if not os.path.exists(path):
print(f"Creating mock audio at {path}...")
import imageio_ffmpeg
import subprocess
exe = imageio_ffmpeg.get_ffmpeg_exe()
subprocess.run([
exe, '-f', 'lavfi', '-i', 'sine=frequency=440:duration=5',
'-t', '5', path, '-y'
], capture_output=True)
return path
def test_full_workflow():
print("\n" + "="*50)
print("๐ STARTING MULTI-PRESET CINEMATIC E2E TEST")
print("="*50)
# 1. Ensure mock assets exist
video_name = create_mock_video_if_needed()
audio_file_path = create_mock_audio()
# List of default presets to test
default_presets = ["youtube_casual", "gaming", "professional", "storyteller"]
transcription = [
{
"text": "Testing all default presets with cinematic style",
"start": 0.0,
"end": 5.0,
"words": [
{"word": "Testing", "start": 0.0, "end": 1.0},
{"word": "all", "start": 1.0, "end": 1.5},
{"word": "default", "start": 1.5, "end": 2.5},
{"word": "presets", "start": 2.5, "end": 3.5},
{"word": "cinematic", "start": 3.5, "end": 5.0}
]
}
]
for preset in default_presets:
print(f"\n[Feature Test] ๐ฌ Cinematic Style + ๐จ Preset: {preset}")
process_data = {
"original_filename": (None, video_name),
"aspect_ratio": (None, "9:16"),
"style": (None, "cinematic"),
"subtitle_style": (None, preset),
"transcription": (None, json.dumps(transcription)),
"timestamps": (None, json.dumps([{"start_time": 0, "end_time": 5}])),
"music_volume": (None, "0.3"),
"video_volume": (None, "1.0"),
"loop_music": (None, "true")
}
with open(audio_file_path, "rb") as f:
files = {"background_music": ("bg.mp3", f, "audio/mpeg")}
resp = client.post("/api/video/process-saved", data=process_data, files=files)
assert resp.status_code == 200, f"Process failed for preset {preset}: {resp.text}"
print(f"โ
Preset '{preset}' processed successfully in Cinematic style.")
# 2. Test Custom Pro Preset with Background Box Color
# 2. Test Word-Based Box Highlight (Box moves with word)
print(f"\n[Feature Test] ๐ Word-Based Box Highlight (Moving Box)")
word_preset_name = "word_box_moving"
word_preset_data = {
"name": (None, word_preset_name),
"font_name": (None, "Impact"),
"font_size": "60",
"primary_color": (None, "#FFFFFF"), # ูุต ุฃุจูุถ
"secondary_color": (None, "#0000FF"), # ุตูุฏูู ุฃุฒุฑู
"box_highlight_type": (None, "word"), # ุงูุตูุฏูู ูุชุญุฑู ู
ุน ุงูููู
ุฉ
"back_box_enabled": (None, "true"),
"pop_up_scale": (None, "1.3"), # ุจูุจ ุฃุจ ููููู
ุฉ
"background_opacity": (None, "0.8")
}
client.post("/api/presets/save", data=word_preset_data)
# 3. Test Sentence-Based Box Highlight (Static Box + Word Popup)
print(f"\n[Feature Test] ๐ผ๏ธ Sentence-Based Box Highlight (Static Box + Word Popup)")
sent_preset_name = "sent_box_static"
sent_preset_data = {
"name": (None, sent_preset_name),
"font_name": (None, "Arial"),
"font_size": "55",
"primary_color": (None, "#FFFFFF"),
"secondary_color": (None, "#00FF00"), # ูุงููุงูุช ุฃุฎุถุฑ
"box_highlight_type": (None, "sentence"), # ุตูุฏูู ุญูู ุงูุฌู
ูุฉ ูููุง
"box_rounding": (None, "15"),
"back_box_enabled": (None, "true"),
"pop_up_scale": (None, "1.4"), # ุจูุจ ุฃุจ ููููู
ุฉ ุฏุงุฎู ุงูุตูุฏูู
"background_opacity": (None, "0.6")
}
client.post("/api/presets/save", data=sent_preset_data)
# Run a test for both
for p_name in [word_preset_name, sent_preset_name]:
process_data = {
"original_filename": (None, video_name),
"aspect_ratio": (None, "9:16"),
"style": (None, "cinematic"),
"subtitle_style": (None, p_name),
"transcription": (None, json.dumps(transcription))
}
resp = client.post("/api/video/process-saved", data=process_data)
assert resp.status_code == 200
print(f"โ
Tested {p_name} successfully.")
# Cleanup
client.delete(f"/api/presets/delete/{word_preset_name}")
client.delete(f"/api/presets/delete/{sent_preset_name}")
process_data_custom = {
"original_filename": (None, video_name),
"aspect_ratio": (None, "9:16"),
"style": (None, "cinematic"),
"subtitle_style": (None, preset_name),
"transcription": (None, json.dumps(transcription))
}
resp = client.post("/api/video/process-saved", data=process_data_custom)
assert resp.status_code == 200
print(f"โ
Custom Preset with Blue Box processed successfully.")
# 3. Cleanup
client.delete(f"/api/presets/delete/{preset_name}")
if os.path.exists(audio_file_path):
os.remove(audio_file_path)
print("\n" + "="*50)
print("๐ ALL MULTI-PRESET TESTS PASSED!")
print("="*50)
if __name__ == "__main__":
test_full_workflow()
|