#!/usr/bin/env python3
"""
Test script to verify the three fixes:
1. Portfolio manager ID deletion error
2. Thermal printer receipts
3. Loading messages removal
"""

import os
import sys

def test_portfolio_deletion_fix():
    """Test that the portfolio_performance table deletion is handled safely"""
    print("🔧 Testing portfolio deletion fix...")
    
    try:
        # Check if the fix is in place
        with open('users/views.py', 'r') as f:
            content = f.read()
            
        if 'portfolio_performance' in content and 'portfolio_manager_id' in content:
            print("✅ Portfolio deletion fix is in place")
            return True
        else:
            print("❌ Portfolio deletion fix not found")
            return False
            
    except Exception as e:
        print(f"❌ Error testing portfolio deletion fix: {e}")
        return False

def test_thermal_printer_fix():
    """Test that thermal printer support is added"""
    print("🔧 Testing thermal printer fix...")
    
    try:
        with open('utils/reports.py', 'r') as f:
            content = f.read()
            
        if 'thermal_printer=False' in content and '3.15*inch' in content:
            print("✅ Thermal printer support is added")
            return True
        else:
            print("❌ Thermal printer support not found")
            return False
            
    except Exception as e:
        print(f"❌ Error testing thermal printer fix: {e}")
        return False

def test_loading_messages_fix():
    """Test that loading messages are removed"""
    print("🔧 Testing loading messages fix...")
    
    try:
        with open('templates/users/client_list.html', 'r') as f:
            content = f.read()
            
        if "loadingDetails.textContent = '';" in content:
            print("✅ Loading messages are removed")
            return True
        else:
            print("❌ Loading messages still present")
            return False
            
    except Exception as e:
        print(f"❌ Error testing loading messages fix: {e}")
        return False

def main():
    """Run all tests"""
    print("🚀 Testing all fixes...\n")
    
    results = []
    results.append(test_portfolio_deletion_fix())
    results.append(test_thermal_printer_fix())
    results.append(test_loading_messages_fix())
    
    print(f"\n📊 Results: {sum(results)}/3 fixes verified")
    
    if all(results):
        print("🎉 All fixes are in place and working!")
        return True
    else:
        print("⚠️  Some fixes may need attention")
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)