Advocate_Life_Style / test_app_startup.py
DocUA's picture
Fix backward compatibility issues with AIClientManager
7605012
#!/usr/bin/env python3
"""
Test that the application can start up without errors
"""
def test_app_imports():
"""Test that all required modules can be imported"""
print("πŸ§ͺ Testing Application Imports\n")
try:
from core_classes import AIClientManager
print(" βœ… AIClientManager imported successfully")
except Exception as e:
print(f" ❌ AIClientManager import error: {e}")
return False
try:
from lifestyle_app import ExtendedLifestyleJourneyApp
print(" βœ… ExtendedLifestyleJourneyApp imported successfully")
except Exception as e:
print(f" ❌ ExtendedLifestyleJourneyApp import error: {e}")
return False
return True
def test_app_initialization():
"""Test that the app can be initialized"""
print("\nπŸ₯ **Testing Application Initialization:**")
try:
from lifestyle_app import ExtendedLifestyleJourneyApp
app = ExtendedLifestyleJourneyApp()
print(" βœ… App initialized successfully")
# Test that API manager is properly set up
if hasattr(app, 'api') and hasattr(app.api, 'call_counter'):
print(f" βœ… API manager ready (call_counter: {app.api.call_counter})")
else:
print(" ❌ API manager not properly initialized")
return False
return True
except Exception as e:
print(f" ❌ App initialization error: {e}")
return False
def test_status_info():
"""Test that _get_status_info works without errors"""
print("\nπŸ“Š **Testing Status Info Generation:**")
try:
from lifestyle_app import ExtendedLifestyleJourneyApp
app = ExtendedLifestyleJourneyApp()
# This was the problematic method
status = app._get_status_info()
print(" βœ… Status info generated successfully")
print(f" Status length: {len(status)} characters")
# Check that it contains expected sections
if "AI STATISTICS" in status:
print(" βœ… AI statistics section present")
else:
print(" ⚠️ AI statistics section missing")
if "AI PROVIDERS STATUS" in status:
print(" βœ… AI providers status section present")
else:
print(" ⚠️ AI providers status section missing")
return True
except Exception as e:
print(f" ❌ Status info error: {e}")
return False
def test_ai_providers_status():
"""Test the new AI providers status method"""
print("\nπŸ€– **Testing AI Providers Status:**")
try:
from lifestyle_app import ExtendedLifestyleJourneyApp
app = ExtendedLifestyleJourneyApp()
# Test the new method
ai_status = app._get_ai_providers_status()
print(" βœ… AI providers status generated successfully")
print(f" Status preview: {ai_status[:100]}...")
return True
except Exception as e:
print(f" ❌ AI providers status error: {e}")
return False
if __name__ == "__main__":
print("πŸš€ Application Startup Test Suite")
print("=" * 50)
success = True
success &= test_app_imports()
success &= test_app_initialization()
success &= test_status_info()
success &= test_ai_providers_status()
print("\nπŸ“‹ **Summary:**")
if success:
print(" βœ… All tests passed - application should start successfully")
print(" βœ… Backward compatibility maintained")
print(" βœ… AI providers integration working")
print(" βœ… Status info generation fixed")
else:
print(" ❌ Some tests failed - check errors above")
print(f"\n{'βœ… SUCCESS' if success else '❌ FAILURE'}: Application startup test {'passed' if success else 'failed'}!")