-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_system.py
More file actions
108 lines (98 loc) · 3.21 KB
/
validate_system.py
File metadata and controls
108 lines (98 loc) · 3.21 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
#!/usr/bin/env python3
"""
Quick system validation script.
"""
import sys
import os
sys.path.append(os.path.dirname(__file__))
def validate_system():
"""Quick system validation."""
print("🧪 Quick System Validation")
print("=" * 40)
tests_passed = 0
tests_failed = 0
# Test 1: Health endpoint
try:
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
response = client.get("/health")
if response.status_code == 200:
print("✅ Health endpoint working")
tests_passed += 1
else:
print("❌ Health endpoint failed")
tests_failed += 1
except Exception as e:
print(f"❌ Health endpoint error: {e}")
tests_failed += 1
# Test 2: Database connection
try:
from app.db import test_db_connection
if test_db_connection():
print("✅ Database connection working")
tests_passed += 1
else:
print("❌ Database connection failed")
tests_failed += 1
except Exception as e:
print(f"❌ Database connection error: {e}")
tests_failed += 1
# Test 3: Redis connection
try:
from app.db import test_redis_connection
if test_redis_connection():
print("✅ Redis connection working")
tests_passed += 1
else:
print("❌ Redis connection failed")
tests_failed += 1
except Exception as e:
print(f"❌ Redis connection error: {e}")
tests_failed += 1
# Test 4: Webhook routing
try:
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
response = client.post("/webhooks/whatsapp", data={
"From": "whatsapp:+1234567890",
"Body": "test",
"MessageSid": "test123"
})
if response.status_code == 200:
print("✅ Webhook routing working")
tests_passed += 1
else:
print("❌ Webhook routing failed")
tests_failed += 1
except Exception as e:
print(f"❌ Webhook routing error: {e}")
tests_failed += 1
# Test 5: Session management
try:
from app.utils.session import SessionManager
session_manager = SessionManager()
session = session_manager.set_session("+1234567890", "test", "start")
if session and session_manager.get_session("+1234567890"):
print("✅ Session management working")
tests_passed += 1
else:
print("❌ Session management failed")
tests_failed += 1
except Exception as e:
print(f"❌ Session management error: {e}")
tests_failed += 1
print("=" * 40)
print(f"✅ Passed: {tests_passed}")
print(f"❌ Failed: {tests_failed}")
if tests_failed == 0:
print("🎉 ALL CORE TESTS PASSED!")
print("🚀 System is ready for Task 5!")
return True
else:
print("⚠️ Some tests failed. Please review.")
return False
if __name__ == "__main__":
success = validate_system()
sys.exit(0 if success else 1)