#!/usr/bin/env python3
"""
Test runner for Amendments API functionality in CongressMCP.
This script runs comprehensive tests for all amendments-related features
and provides a detailed summary of results.
"""
import sys
import os
import time
from datetime import datetime
# Add the parent directory to the Python path for imports
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
def run_amendments_tests():
"""Run all amendments tests and provide detailed output."""
print("๐ Starting Amendments API Tests...")
print(f"๐
Test Run: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 70)
try:
# Import and run the test module
from test_amendments_functionality import run_amendments_tests as run_tests
start_time = time.time()
results = run_tests()
end_time = time.time()
print("\n" + "=" * 70)
print("๐ AMENDMENTS API TEST RESULTS")
print("=" * 70)
# Display detailed results
print(f"โฑ๏ธ Execution Time: {end_time - start_time:.2f} seconds")
print(f"๐งช Total Tests: {results['tests_run']}")
print(f"โ
Passed: {results['tests_run'] - results['failures'] - results['errors']}")
print(f"โ Failed: {results['failures']}")
print(f"๐ฅ Errors: {results['errors']}")
# Overall status
if results['success']:
print("\n๐ OVERALL STATUS: ALL TESTS PASSED! โ
")
print("\n๐ Test Categories Verified:")
print(" โ
Amendment formatting functions")
print(" โ
Search patterns and keyword filtering")
print(" โ
API integration patterns")
print(" โ
Error handling and edge cases")
print("\n๐ง Amendments API Features Tested:")
print(" โ
format_amendment_summary() - Brief amendment overviews")
print(" โ
format_amendment_details() - Detailed amendment information")
print(" โ
format_amendment_action() - Legislative action formatting")
print(" โ
Keyword search validation")
print(" โ
Amendment type validation (SAMDT, HAMDT)")
print(" โ
Congress number validation")
print(" โ
Missing data handling")
print(" โ
Invalid parameter detection")
print("\n๐ฏ Production Readiness:")
print(" โ
All formatting functions handle missing data gracefully")
print(" โ
Search patterns support current and historical congresses")
print(" โ
Error handling prevents crashes with invalid inputs")
print(" โ
API integration follows Congressional MCP patterns")
else:
print(f"\nโ ๏ธ OVERALL STATUS: {results['failures'] + results['errors']} TEST(S) FAILED โ")
print("\n๐ Please review the detailed test output above to identify issues.")
print("๐ก Common issues to check:")
print(" - Missing import dependencies")
print(" - Incorrect function signatures")
print(" - API response format changes")
print(" - Invalid test data assumptions")
print("\n" + "=" * 70)
return results['success']
except ImportError as e:
print(f"โ Import Error: {e}")
print("๐ก Make sure you're running from the CongressMCP/tests/ directory")
print("๐ก Verify all required modules are available")
return False
except Exception as e:
print(f"๐ฅ Unexpected Error: {e}")
print("๐ก Check the test file for syntax errors or missing dependencies")
return False
def main():
"""Main function to run amendments tests."""
print("๐๏ธ CONGRESSIONAL MCP - AMENDMENTS API TEST SUITE")
print("=" * 70)
print("๐ Testing all amendments-related functionality...")
print("๐ Validating formatting, search patterns, and error handling")
print()
success = run_amendments_tests()
if success:
print("\n๐ Amendments API testing completed successfully!")
print("๐ All amendments functionality is ready for production use.")
exit_code = 0
else:
print("\n๐จ Amendments API testing failed!")
print("๐ง Please fix the issues before deploying amendments functionality.")
exit_code = 1
print("\n๐ Next Steps:")
if success:
print(" 1. โ
Amendments API is fully tested and functional")
print(" 2. ๐งช Consider testing other Congressional MCP features")
print(" 3. ๐ Run integration tests with production API")
print(" 4. ๐ Deploy with confidence!")
else:
print(" 1. ๐ Review test failures and fix underlying issues")
print(" 2. ๐งช Re-run tests after making corrections")
print(" 3. ๐ Update test cases if API behavior has changed")
print(" 4. ๐ Repeat until all tests pass")
return exit_code
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)