CoolFace
Apppublic

findEthics/Atlas

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
deployment_check.py157 linesDownload Raw Back to tests
1#!/usr/bin/env python32"""3Deployment readiness check for Atlas analytics system4"""5import asyncio6import os7import sys8from dotenv import load_dotenv9 10load_dotenv()11 12async def check_environment_variables():13    """Check if all required environment variables are set"""14    print("๐Ÿ” Environment Variables Check")15    print("=" * 40)16    17    required_vars = {18        "GOOGLE_API_KEY": "Google Gemini API",19        "BRAVE_API_KEY": "Brave Search API", 20        "MONGODB_URL": "MongoDB Atlas connection",21        "MONGODB_DATABASE": "MongoDB database name"22    }23    24    all_set = True25    for var, description in required_vars.items():26        value = os.getenv(var)27        if value:28            print(f"โœ… {var}: Set ({description})")29        else:30            print(f"โŒ {var}: Missing ({description})")31            all_set = False32    33    return all_set34 35async def check_database_connection():36    """Check MongoDB connection"""37    print("\n๐Ÿ—„๏ธ  Database Connection Check")38    print("=" * 40)39    40    try:41        from analytics.database import test_connection42        connected = await test_connection()43        44        if connected:45            print("โœ… MongoDB connection successful")46            return True47        else:48            print("โŒ MongoDB connection failed")49            return False50            51    except Exception as e:52        print(f"โŒ Database connection error: {e}")53        return False54 55async def check_analytics_system():56    """Check analytics system functionality"""57    print("\n๐Ÿ“Š Analytics System Check")58    print("=" * 40)59    60    try:61        # Test dashboard62        from analytics.dashboard import get_basic_stats63        stats = await get_basic_stats()64        65        if "error" in stats:66            print(f"โŒ Dashboard error: {stats['error']}")67            return False68        else:69            print("โœ… Dashboard working")70            print(f"   Sessions: {stats.get('total_sessions', 0)}")71            print(f"   Messages: {stats.get('total_messages', 0)}")72            73        # Test collectors74        from analytics.collectors import create_session75        test_session = await create_session(user_agent="Deployment Test")76        77        if test_session:78            print("โœ… Session creation working")79        else:80            print("โŒ Session creation failed")81            return False82            83        return True84        85    except Exception as e:86        print(f"โŒ Analytics system error: {e}")87        return False88 89async def check_dependencies():90    """Check if all required packages are available"""91    print("\n๐Ÿ“ฆ Dependencies Check")92    print("=" * 40)93    94    required_packages = [95        ("fastapi", "FastAPI web framework"),96        ("motor", "MongoDB async driver"),97        ("google.generativeai", "Google Gemini API"),98        ("httpx", "HTTP client"),99        ("pydantic", "Data validation"),100        ("dotenv", "Environment variables")101    ]102    103    all_available = True104    for package, description in required_packages:105        try:106            __import__(package.replace("-", "_"))107            print(f"โœ… {package}: Available ({description})")108        except ImportError:109            print(f"โŒ {package}: Missing ({description})")110            all_available = False111    112    return all_available113 114async def main():115    """Run all deployment checks"""116    print("๐Ÿš€ Atlas Analytics Deployment Check")117    print("=" * 50)118    119    checks = [120        ("Environment Variables", check_environment_variables()),121        ("Dependencies", check_dependencies()),122        ("Database Connection", check_database_connection()),123        ("Analytics System", check_analytics_system())124    ]125    126    results = []127    for name, check_coro in checks:128        try:129            result = await check_coro130            results.append((name, result))131        except Exception as e:132            print(f"โŒ {name} check failed: {e}")133            results.append((name, False))134    135    # Summary136    print("\n๐Ÿ“‹ Deployment Readiness Summary")137    print("=" * 50)138    139    all_passed = True140    for name, passed in results:141        status = "โœ… PASS" if passed else "โŒ FAIL"142        print(f"{status} {name}")143        if not passed:144            all_passed = False145    146    print("\n" + "=" * 50)147    if all_passed:148        print("๐ŸŽ‰ DEPLOYMENT READY: All checks passed!")149        print("   You can deploy the Atlas analytics system.")150        sys.exit(0)151    else:152        print("โš ๏ธ  DEPLOYMENT NOT READY: Some checks failed.")153        print("   Please fix the issues above before deploying.")154        sys.exit(1)155 156if __name__ == "__main__":157    asyncio.run(main())