
#!/usr/bin/env python3
"""
Start RateRight server and test live endpoints
"""

import subprocess
import time
import sys
import signal
import os

def main():
    print("🚀 STARTING RATERIGHT SERVER AND TESTING ENDPOINTS")
    print("=" * 60)
    
    # Start the Flask server
    print("🔧 Starting Flask server...")
    server_process = subprocess.Popen([sys.executable, 'run.py'])
    
    try:
        # Give server time to start
        print("⏳ Waiting for server to start...")
        time.sleep(4)
        
        # Run the authentication tests
        print("🧪 Running authentication tests...")
        test_process = subprocess.run([sys.executable, 'test_auth_endpoints.py'])
        
        print("\n✅ Testing complete!")
        
    except KeyboardInterrupt:
        print("\n🛑 Interrupted by user")
    finally:
        # Clean up server process
        print("🔧 Shutting down server...")
        server_process.terminate()
        server_process.wait()
        print("✅ Server stopped")

if __name__ == "__main__":
    main()
