Spaces:
Sleeping
Sleeping
File size: 4,578 Bytes
f6278c5 | 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 | #!/usr/bin/env python3
"""
Test runner for authentication system tests
Runs both unit tests and integration tests with proper reporting
"""
import unittest
import sys
import os
from io import StringIO
# Add parent directory to Python path so we can import the main modules
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def run_tests():
"""Run all authentication tests and generate report"""
# Create test suite
loader = unittest.TestLoader()
suite = unittest.TestSuite()
# Load unit tests
try:
from test_auth_unit import (
TestUserModel, TestChatSessionModel,
TestAuthenticationUtilities, TestLoginRequiredDecorator
)
suite.addTests(loader.loadTestsFromTestCase(TestUserModel))
suite.addTests(loader.loadTestsFromTestCase(TestChatSessionModel))
suite.addTests(loader.loadTestsFromTestCase(TestAuthenticationUtilities))
suite.addTests(loader.loadTestsFromTestCase(TestLoginRequiredDecorator))
print("β Unit tests loaded successfully")
except ImportError as e:
print(f"β Failed to load unit tests: {e}")
return False
# Load integration tests
try:
from test_auth_simple import TestSimpleAuthenticationFlows
suite.addTests(loader.loadTestsFromTestCase(TestSimpleAuthenticationFlows))
print("β Integration tests loaded successfully")
except ImportError as e:
print(f"β Failed to load integration tests: {e}")
return False
# Run tests with detailed output
print("\n" + "="*60)
print("RUNNING AUTHENTICATION SYSTEM TESTS")
print("="*60)
# Capture test output
stream = StringIO()
runner = unittest.TextTestRunner(
stream=stream,
verbosity=2,
buffer=True,
failfast=False
)
result = runner.run(suite)
# Print results
output = stream.getvalue()
print(output)
# Print summary
print("\n" + "="*60)
print("TEST SUMMARY")
print("="*60)
print(f"Tests run: {result.testsRun}")
print(f"Failures: {len(result.failures)}")
print(f"Errors: {len(result.errors)}")
print(f"Skipped: {len(result.skipped) if hasattr(result, 'skipped') else 0}")
if result.failures:
print(f"\nβ FAILURES ({len(result.failures)}):")
for test, traceback in result.failures:
print(f" - {test}")
if result.errors:
print(f"\nπ₯ ERRORS ({len(result.errors)}):")
for test, traceback in result.errors:
print(f" - {test}")
success_rate = ((result.testsRun - len(result.failures) - len(result.errors)) / result.testsRun * 100) if result.testsRun > 0 else 0
print(f"\nπ Success Rate: {success_rate:.1f}%")
if result.wasSuccessful():
print("\nπ ALL TESTS PASSED!")
return True
else:
print(f"\nβ {len(result.failures) + len(result.errors)} TEST(S) FAILED")
return False
def run_specific_test_class(test_class_name):
"""Run a specific test class"""
# Map test class names to modules
test_classes = {
'TestUserModel': 'test_auth_unit',
'TestChatSessionModel': 'test_auth_unit',
'TestAuthenticationUtilities': 'test_auth_unit',
'TestLoginRequiredDecorator': 'test_auth_unit',
'TestSimpleAuthenticationFlows': 'test_auth_simple'
}
if test_class_name not in test_classes:
print(f"β Unknown test class: {test_class_name}")
print(f"Available classes: {', '.join(test_classes.keys())}")
return False
try:
module_name = test_classes[test_class_name]
module = __import__(module_name)
test_class = getattr(module, test_class_name)
suite = unittest.TestLoader().loadTestsFromTestCase(test_class)
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return result.wasSuccessful()
except Exception as e:
print(f"β Error running test class {test_class_name}: {e}")
return False
def main():
"""Main entry point"""
if len(sys.argv) > 1:
# Run specific test class
test_class = sys.argv[1]
success = run_specific_test_class(test_class)
else:
# Run all tests
success = run_tests()
# Exit with appropriate code
sys.exit(0 if success else 1)
if __name__ == '__main__':
main() |