-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fix.py
More file actions
116 lines (96 loc) · 3.11 KB
/
test_fix.py
File metadata and controls
116 lines (96 loc) · 3.11 KB
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
#!/usr/bin/env python3
"""
Test script to verify the bug fix for Horizon Exam Bot
Tests that essential dependencies can be imported and the Flask app can start
"""
import sys
import subprocess
import time
import requests
from threading import Thread
def test_dependencies():
"""Test that essential dependencies can be imported"""
print("🧪 Testing essential dependencies...")
try:
import flask
print("✅ Flask imported successfully")
except ImportError:
print("❌ Flask import failed")
return False
try:
import PyPDF2
print("✅ PyPDF2 imported successfully")
except ImportError:
print("❌ PyPDF2 import failed")
return False
try:
from docx import Document
print("✅ python-docx imported successfully")
except ImportError:
print("❌ python-docx import failed")
return False
return True
def test_app_import():
"""Test that the Flask app can be imported"""
print("\n🧪 Testing Flask app import...")
try:
from app import app
print("✅ Flask app imported successfully")
return True
except Exception as e:
print(f"❌ Flask app import failed: {e}")
return False
def test_app_startup():
"""Test that the Flask app can start"""
print("\n🧪 Testing Flask app startup...")
# Start the app in a subprocess
process = subprocess.Popen([sys.executable, "run.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Give it time to start
time.sleep(3)
try:
# Test if the app is running
response = requests.get("http://localhost:5000/", timeout=5)
if response.status_code == 200:
print("✅ Flask app started successfully")
print("✅ Main page is accessible")
success = True
else:
print(f"❌ App responded with status code: {response.status_code}")
success = False
except requests.exceptions.RequestException as e:
print(f"❌ Failed to connect to app: {e}")
success = False
finally:
# Clean up the process
process.terminate()
try:
process.wait(timeout=5)
except subprocess.TimeoutExpired:
process.kill()
return success
def main():
"""Run all tests"""
print("🔧 Testing Horizon Exam Bot Bug Fix")
print("=" * 50)
all_passed = True
# Test 1: Dependencies
if not test_dependencies():
all_passed = False
# Test 2: App import
if not test_app_import():
all_passed = False
# Test 3: App startup
if not test_app_startup():
all_passed = False
print("\n" + "=" * 50)
if all_passed:
print("🎉 All tests passed! Bug fix is successful!")
print("✅ The application can now run with minimal dependencies")
return 0
else:
print("❌ Some tests failed. Bug fix needs more work.")
return 1
if __name__ == "__main__":
sys.exit(main())