File size: 3,754 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
اختبار مشكلة endpoint التلخيص
"""

import requests
import json

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

def test_summarize_endpoint():
    """اختبار endpoint التلخيص"""
    print("\n🤖 اختبار endpoint التلخيص...")
    
    test_data = {
        "text": "Hello, how are you? What are you doing today? Tell me.",
        "language": "arabic"
    }
    
    try:
        response = requests.post(
            'http://localhost:5001/summarize',
            json=test_data,
            headers={'Content-Type': 'application/json'}
        )
        
        print(f"Status Code: {response.status_code}")
        print(f"Response: {response.text}")
        
        if response.status_code == 200:
            data = response.json()
            if data.get('success'):
                print("✅ التلخيص نجح!")
                return True
            else:
                print(f"❌ فشل التلخيص: {data.get('error')}")
                return False
        else:
            print(f"❌ خطأ HTTP: {response.status_code}")
            return False
            
    except Exception as e:
        print(f"❌ خطأ في طلب POST: {e}")
        return False

def test_server_status():
    """اختبار حالة الخادم"""
    print("🌐 اختبار حالة الخادم...")
    
    try:
        response = requests.get('http://localhost:5001/record')
        print(f"Status Code: {response.status_code}")
        
        if response.status_code == 200:
            data = response.json()
            print(f"Server Status: {data.get('status')}")
            return True
        else:
            print(f"❌ الخادم غير متاح: {response.status_code}")
            return False
            
    except Exception as e:
        print(f"❌ لا يمكن الوصول للخادم: {e}")
        return False

if __name__ == "__main__":
    print("=" * 50)
    print("🚀 بدء اختبار مشكلة التلخيص")
    print("=" * 50)
    
    # اختبار حالة الخادم
    server_ok = test_server_status()
    
    if server_ok:
        # اختبار CORS
        cors_ok = test_cors_preflight()
        
        if cors_ok:
            # اختبار التلخيص
            summarize_ok = test_summarize_endpoint()
            
            if summarize_ok:
                print("\n🎉 جميع الاختبارات نجحت!")
            else:
                print("\n❌ فشل في اختبار التلخيص")
        else:
            print("\n❌ مشكلة في CORS - يجب إعادة تشغيل الخادم")
    else:
        print("\n❌ الخادم غير متاح - يجب تشغيله أولاً")
    
    print("=" * 50)