File size: 7,806 Bytes
f93a960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
اختبار شامل للتحقق من إصلاح جميع المشاكل
"""

import requests
import json
import time

def test_server_health():
    """اختبار صحة الخادم"""
    print("🏥 اختبار صحة الخادم...")
    
    try:
        response = requests.get('http://localhost:5001/record', timeout=5)
        if response.status_code == 200:
            data = response.json()
            print(f"✅ الخادم يعمل: {data.get('message')}")
            return True
        else:
            print(f"❌ مشكلة في الخادم: {response.status_code}")
            return False
    except Exception as e:
        print(f"❌ لا يمكن الوصول للخادم: {e}")
        return False

def test_cors_headers():
    """اختبار CORS headers"""
    print("\n🔧 اختبار CORS headers...")
    
    try:
        # اختبار OPTIONS request
        response = requests.options('http://localhost:5001/summarize', timeout=5)
        
        print(f"Status Code: {response.status_code}")
        
        # فحص CORS headers
        cors_origin = response.headers.get('Access-Control-Allow-Origin')
        cors_methods = response.headers.get('Access-Control-Allow-Methods')
        cors_headers = response.headers.get('Access-Control-Allow-Headers')
        
        print(f"CORS Origin: '{cors_origin}'")
        print(f"CORS Methods: '{cors_methods}'")
        print(f"CORS Headers: '{cors_headers}'")
        
        # التحقق من عدم وجود قيم مكررة
        if cors_origin and ',' in cors_origin and cors_origin.count('*') > 1:
            print("❌ مشكلة: CORS Origin يحتوي على قيم مكررة!")
            return False
        elif cors_origin == '*':
            print("✅ CORS Origin صحيح")
            return True
        else:
            print(f"⚠️ CORS Origin غير متوقع: {cors_origin}")
            return False
            
    except Exception as e:
        print(f"❌ خطأ في اختبار CORS: {e}")
        return False

def test_summarization():
    """اختبار وظيفة التلخيص"""
    print("\n🤖 اختبار وظيفة التلخيص...")
    
    test_data = {
        "text": "Hello, how are you? What are you doing today? Tell me about your work and your plans.",
        "language": "arabic",
        "type": "full"
    }
    
    try:
        response = requests.post(
            'http://localhost:5001/summarize',
            json=test_data,
            headers={'Content-Type': 'application/json'},
            timeout=30
        )
        
        print(f"Status Code: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            if data.get('success'):
                print("✅ التلخيص نجح!")
                summary = data.get('summary', '')
                print(f"الملخص: {summary[:100]}...")
                return True
            else:
                print(f"❌ فشل التلخيص: {data.get('error')}")
                return False
        else:
            print(f"❌ خطأ HTTP: {response.status_code}")
            print(f"الرد: {response.text}")
            return False
            
    except Exception as e:
        print(f"❌ خطأ في اختبار التلخيص: {e}")
        return False

def test_javascript_syntax():
    """اختبار صيغة JavaScript"""
    print("\n📝 اختبار صيغة JavaScript...")
    
    try:
        with open('templates/recorder.html', 'r', encoding='utf-8') as f:
            content = f.read()
        
        # فحص بسيط للأقواس
        js_start = content.find('<script>')
        js_end = content.find('</script>')
        
        if js_start == -1 or js_end == -1:
            print("❌ لا يمكن العثور على JavaScript")
            return False
        
        js_content = content[js_start:js_end]
        
        # عد الأقواس
        open_braces = js_content.count('{')
        close_braces = js_content.count('}')
        
        print(f"أقواس فتح: {open_braces}")
        print(f"أقواس إغلاق: {close_braces}")
        
        if open_braces == close_braces:
            print("✅ الأقواس متوازنة")
            
            # فحص للكلمات المفتاحية الأساسية
            if 'function' in js_content and 'async function' in js_content:
                print("✅ الدوال موجودة")
                return True
            else:
                print("⚠️ لا يمكن العثور على الدوال")
                return False
        else:
            print(f"❌ الأقواس غير متوازنة! الفرق: {open_braces - close_braces}")
            return False
            
    except Exception as e:
        print(f"❌ خطأ في فحص JavaScript: {e}")
        return False

def test_translation_endpoints():
    """اختبار endpoints الترجمة"""
    print("\n🌐 اختبار endpoints الترجمة...")
    
    try:
        # اختبار قائمة اللغات
        response = requests.get('http://localhost:5001/languages', timeout=5)
        if response.status_code == 200:
            print("✅ endpoint اللغات يعمل")
        else:
            print(f"⚠️ مشكلة في endpoint اللغات: {response.status_code}")
        
        # اختبار UI translations
        response = requests.get('http://localhost:5001/ui-translations/en', timeout=5)
        if response.status_code == 200:
            print("✅ endpoint UI translations يعمل")
        else:
            print(f"⚠️ مشكلة في endpoint UI translations: {response.status_code}")
        
        return True
        
    except Exception as e:
        print(f"❌ خطأ في اختبار endpoints الترجمة: {e}")
        return False

def comprehensive_test():
    """اختبار شامل لجميع الوظائف"""
    print("🚀 بدء الاختبار الشامل")
    print("=" * 60)
    
    tests = [
        ("صحة الخادم", test_server_health),
        ("CORS Headers", test_cors_headers),
        ("وظيفة التلخيص", test_summarization),
        ("صيغة JavaScript", test_javascript_syntax),
        ("endpoints الترجمة", test_translation_endpoints)
    ]
    
    results = []
    
    for test_name, test_func in tests:
        print(f"\n🧪 اختبار: {test_name}")
        print("-" * 40)
        
        try:
            result = test_func()
            results.append((test_name, result))
            
            if result:
                print(f"✅ {test_name}: نجح")
            else:
                print(f"❌ {test_name}: فشل")
                
        except Exception as e:
            print(f"❌ {test_name}: خطأ - {e}")
            results.append((test_name, False))
    
    # النتائج النهائية
    print("\n" + "=" * 60)
    print("📊 ملخص نتائج الاختبار:")
    print("=" * 60)
    
    passed = 0
    total = len(results)
    
    for test_name, result in results:
        status = "✅ نجح" if result else "❌ فشل"
        print(f"  {test_name}: {status}")
        if result:
            passed += 1
    
    print(f"\nالنتيجة النهائية: {passed}/{total} اختبارات نجحت")
    
    if passed == total:
        print("🎉 جميع الاختبارات نجحت! النظام يعمل بشكل مثالي")
        return True
    else:
        print(f"⚠️ {total - passed} اختبارات فشلت - هناك مشاكل تحتاج إصلاح")
        return False

if __name__ == "__main__":
    comprehensive_test()