File size: 2,754 Bytes
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
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