Spaces:
Sleeping
Sleeping
| #!/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() | |