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