Clipping / tests /test_subtitle_workflow.py
aliSaac510's picture
add sub endpoints
c63c39e
import json
import os
import sys
import pytest
from fastapi.testclient import TestClient
# إضافة مجلد Clipping للمسار لتمكين الاستيراد
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.presets import PRESETS_DIR
client = TestClient(app)
def test_preset_save_and_load():
"""اختبار حفظ البريسيت واستعادته"""
preset_name = "test_unit_style"
# 1. حفظ البريسيت
data = {
"name": (None, preset_name),
"font_name": (None, "Arial"),
"font_size": (None, "50"),
"primary_color": (None, "#FF5733"),
"back_box_enabled": (None, "true")
}
response = client.post("/api/presets/save", data=data)
assert response.status_code == 200
assert response.json()["status"] == "success"
# 2. التأكد من وجود الملف في المجلد
file_path = os.path.join(PRESETS_DIR, f"{preset_name}.json")
assert os.path.exists(file_path)
# 3. التأكد من ظهور البريسيت في القائمة
list_response = client.get("/api/presets/list")
assert preset_name in list_response.json()
def test_video_process_with_preset_mock():
"""اختبار دمج البريسيت في عملية المعالجة (Mock)"""
preset_name = "test_unit_style"
mock_transcription = [
{"word": "Hello", "start": 0.0, "end": 1.0},
{"word": "World", "start": 1.0, "end": 2.0}
]
# محاكاة رفع فيديو
dummy_video = "test_dummy.mp4"
with open(dummy_video, "wb") as f:
f.write(b"dummy video content")
try:
with open(dummy_video, "rb") as video_file:
files = {"video": ("test.mp4", video_file, "video/mp4")}
data = {
"subtitle_style": preset_name,
"transcription": json.dumps(mock_transcription),
"aspect_ratio": "9:16",
"style": "original"
}
response = client.post("/api/video/process", data=data, files=files)
if response.status_code != 200:
print(f"Error Response: {response.json()}")
assert response.status_code == 200
assert "task_id" in response.json()
finally:
if os.path.exists(dummy_video):
os.remove(dummy_video)
def test_cleanup_presets():
"""تنظيف بيانات الاختبار"""
preset_name = "test_unit_style"
response = client.delete(f"/api/presets/delete/{preset_name}")
assert response.status_code == 200