run_all_tests.pyโข6.1 kB
#!/usr/bin/env python3
"""
Comprehensive test runner for TimeLooker MCP Server.
Runs all available tests including x402 integration and API tests.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from src.utils.logging_config import setup_logging
logger = setup_logging(__name__)
def run_all_tests():
"""Run all available tests."""
print("๐งช COMPREHENSIVE TEST SUITE")
print("=" * 60)
print("Running all TimeLooker tests...")
print("=" * 60)
success_count = 0
total_tests = 0
# 1. Search Quality Tests
print("\n1๏ธโฃ SEARCH QUALITY TESTS")
print("-" * 30)
try:
from quick_quality_test import quick_search_test
quick_search_test()
success_count += 1
logger.info("โ
Search quality tests passed")
except Exception as e:
logger.error(f"โ Search quality tests failed: {e}")
total_tests += 1
# 2. X402 Payment Integration Tests
print("\n2๏ธโฃ X402 PAYMENT INTEGRATION TESTS")
print("-" * 30)
try:
from test_x402_integration import run_x402_tests
if run_x402_tests():
success_count += 1
logger.info("โ
X402 integration tests passed")
else:
logger.error("โ X402 integration tests failed")
except Exception as e:
logger.error(f"โ X402 integration tests failed: {e}")
total_tests += 1
# 3. API Integration Tests
print("\n3๏ธโฃ API INTEGRATION TESTS")
print("-" * 30)
try:
from test_api_integration import run_api_integration_tests
if run_api_integration_tests():
success_count += 1
logger.info("โ
API integration tests passed")
else:
logger.error("โ API integration tests failed")
except Exception as e:
logger.error(f"โ API integration tests failed: {e}")
total_tests += 1
# 4. Lambda Function Tests
print("\n4๏ธโฃ LAMBDA FUNCTION TESTS")
print("-" * 30)
try:
from test_lambda import LambdaTester
tester = LambdaTester()
# Test create task event
create_event = {
"action": "create_task",
"task_description": "Test monitoring task",
"frequency_minutes": 60,
"runtime_minutes": 1440,
"recipient_email": "test@example.com"
}
result = tester.invoke_lambda(create_event, "Test create task")
if result and "task_id" in result.get("body", ""):
success_count += 1
logger.info("โ
Lambda function tests passed")
else:
logger.error("โ Lambda function tests failed")
except Exception as e:
logger.error(f"โ Lambda function tests failed: {e}")
total_tests += 1
# Summary
print("\n" + "=" * 60)
print("๐ TEST SUMMARY")
print("=" * 60)
print(f"Tests passed: {success_count}/{total_tests}")
if success_count == total_tests:
print("๐ ALL TESTS PASSED!")
logger.info("All tests completed successfully")
return True
else:
print(f"โ ๏ธ {total_tests - success_count} test(s) failed")
logger.warning(f"{total_tests - success_count} test(s) failed")
return False
def run_specific_test_category():
"""Run a specific category of tests."""
print("๐ฏ SPECIFIC TEST CATEGORIES")
print("=" * 40)
print("1. Search Quality Tests Only")
print("2. X402 Payment Tests Only")
print("3. API Integration Tests Only")
print("4. Lambda Function Tests Only")
print("5. All Tests (recommended)")
print("0. Exit")
choice = input("\nSelect test category (0-5): ").strip()
if choice == "1":
from quick_quality_test import quick_search_test
quick_search_test()
elif choice == "2":
from test_x402_integration import run_x402_tests
run_x402_tests()
elif choice == "3":
from test_api_integration import run_api_integration_tests
run_api_integration_tests()
elif choice == "4":
from test_lambda import LambdaTester
tester = LambdaTester()
print("Running basic lambda function test...")
# Add basic lambda test here
elif choice == "5":
return run_all_tests()
elif choice == "0":
print("๐ Goodbye!")
return True
else:
print("โ Invalid choice")
return False
def main():
"""Main function."""
print("Welcome to the TimeLooker Test Suite!")
print("\n๐ Available Options:")
print("โข Run all tests (comprehensive)")
print("โข Run specific test categories")
print("โข View test documentation")
while True:
print("\n" + "=" * 40)
print("1. Run All Tests")
print("2. Run Specific Test Category")
print("3. View Test Documentation")
print("0. Exit")
choice = input("\nSelect option (0-3): ").strip()
if choice == "1":
success = run_all_tests()
break
elif choice == "2":
success = run_specific_test_category()
break
elif choice == "3":
print("\n๐ TEST DOCUMENTATION")
print("=" * 30)
print("โข Search Quality Tests: Validate search result quality and duplicate detection")
print("โข X402 Payment Tests: Test payment integration flows (mocked)")
print("โข API Integration Tests: Test FastAPI endpoints and database integration")
print("โข Lambda Function Tests: Test AWS Lambda compatibility")
print("\n๐ก For interactive testing, use: python run_quality_tests.py")
continue
elif choice == "0":
print("๐ Goodbye!")
success = True
break
else:
print("โ Invalid option")
continue
return success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)