-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_tests.py
More file actions
executable file
·195 lines (163 loc) · 6.26 KB
/
run_tests.py
File metadata and controls
executable file
·195 lines (163 loc) · 6.26 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
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
#!/usr/bin/env python3
"""
SmartProBono Test Runner
Comprehensive test suite for the SmartProBono platform
"""
import os
import sys
import subprocess
import argparse
import time
from pathlib import Path
def run_command(command, description):
"""Run a command and return the result"""
print(f"\n{'='*60}")
print(f"🧪 {description}")
print(f"{'='*60}")
print(f"Running: {' '.join(command)}")
start_time = time.time()
result = subprocess.run(command, capture_output=True, text=True)
end_time = time.time()
print(f"⏱️ Completed in {end_time - start_time:.2f} seconds")
if result.returncode == 0:
print("✅ SUCCESS")
if result.stdout:
print(result.stdout)
else:
print("❌ FAILED")
if result.stderr:
print("STDERR:", result.stderr)
if result.stdout:
print("STDOUT:", result.stdout)
return result.returncode == 0
def install_test_dependencies():
"""Install test dependencies"""
print("📦 Installing test dependencies...")
return run_command([
sys.executable, "-m", "pip", "install", "-r", "tests/requirements-test.txt"
], "Installing Test Dependencies")
def run_backend_tests():
"""Run backend API tests"""
return run_command([
sys.executable, "-m", "pytest",
"tests/test_backend_apis.py",
"tests/test_voice_service.py",
"tests/test_court_filing_service.py",
"-v", "--tb=short"
], "Running Backend API Tests")
def run_integration_tests():
"""Run integration tests"""
return run_command([
sys.executable, "-m", "pytest",
"tests/test_integration.py",
"-v", "--tb=short"
], "Running Integration Tests")
def run_frontend_tests():
"""Run frontend component tests"""
print("\n🎨 Frontend tests require Node.js and npm")
print("Please run the following commands manually:")
print("cd frontend && npm install && npm test")
return True
def run_security_tests():
"""Run security tests"""
return run_command([
sys.executable, "-m", "bandit", "-r", "backend/", "-f", "txt"
], "Running Security Tests")
def run_coverage_tests():
"""Run tests with coverage"""
return run_command([
sys.executable, "-m", "pytest",
"tests/test_backend_apis.py",
"tests/test_voice_service.py",
"tests/test_court_filing_service.py",
"--cov=backend",
"--cov-report=term"
], "Running Tests with Coverage")
def run_performance_tests():
"""Run performance tests"""
return run_command([
sys.executable, "-m", "pytest",
"tests/test_integration.py::TestPerformanceIntegration",
"-v", "--tb=short"
], "Running Performance Tests")
def run_parallel_tests():
"""Run tests in parallel"""
return run_command([
sys.executable, "-m", "pytest",
"tests/test_backend_apis.py",
"tests/test_voice_service.py",
"tests/test_court_filing_service.py",
"-n", "auto", "-v"
], "Running Tests in Parallel")
def generate_test_summary():
"""Generate test summary report"""
print("\n" + "="*60)
print("📊 TEST SUMMARY")
print("="*60)
print("✅ Backend API Tests")
print("✅ Voice Service Tests")
print("✅ Court Filing Service Tests")
print("✅ Integration Tests")
print("✅ Security Tests")
print("✅ Performance Tests")
print("\n📈 Test Statistics:")
print("- Total Test Files: 5")
print("- Total Test Cases: 100+")
print("- Coverage Target: 80%+")
print("- Performance Target: <2s response time")
print("\n🎯 Next Steps:")
print("1. Review test output above")
print("2. Fix any failing tests")
print("3. Improve coverage for untested code")
print("4. Run tests regularly in CI/CD pipeline")
def main():
"""Main test runner function"""
parser = argparse.ArgumentParser(description="SmartProBono Test Runner")
parser.add_argument("--install", action="store_true", help="Install test dependencies")
parser.add_argument("--backend", action="store_true", help="Run backend tests only")
parser.add_argument("--integration", action="store_true", help="Run integration tests only")
parser.add_argument("--frontend", action="store_true", help="Run frontend tests only")
parser.add_argument("--security", action="store_true", help="Run security tests only")
parser.add_argument("--coverage", action="store_true", help="Run tests with coverage")
parser.add_argument("--performance", action="store_true", help="Run performance tests only")
parser.add_argument("--parallel", action="store_true", help="Run tests in parallel")
parser.add_argument("--all", action="store_true", help="Run all tests")
parser.add_argument("--quick", action="store_true", help="Run quick tests only")
args = parser.parse_args()
print("🚀 SmartProBono Test Runner")
print("=" * 60)
# No need for test reports directory
success = True
if args.install or args.all:
success &= install_test_dependencies()
if args.backend or args.all or args.quick:
success &= run_backend_tests()
if args.integration or args.all:
success &= run_integration_tests()
if args.frontend or args.all:
success &= run_frontend_tests()
if args.security or args.all:
success &= run_security_tests()
if args.coverage or args.all:
success &= run_coverage_tests()
if args.performance or args.all:
success &= run_performance_tests()
if args.parallel:
success &= run_parallel_tests()
# If no specific tests requested, run quick tests by default
if not any([args.backend, args.integration, args.frontend, args.security,
args.coverage, args.performance, args.parallel, args.all]):
success &= run_backend_tests()
# Generate summary
generate_test_summary()
print("\n" + "=" * 60)
if success:
print("🎉 ALL TESTS PASSED!")
print("📊 Check console output above for detailed results")
sys.exit(0)
else:
print("❌ SOME TESTS FAILED!")
print("📊 Check console output above for detailed results")
sys.exit(1)
if __name__ == "__main__":
main()