#!/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)