#!/usr/bin/env python3 """ Test script to verify all DataOps database connections for Elizabeth """ import os import sys import redis import chromadb import psycopg2 import pymongo import qdrant_client from datetime import datetime def test_redis(): """Test Redis connection""" try: client = redis.Redis(host='localhost', port=6379, decode_responses=True) client.ping() print("✅ Redis: Connected successfully") return True except Exception as e: print(f"❌ Redis: Connection failed - {e}") return False def test_postgresql(): """Test PostgreSQL connection""" try: conn = psycopg2.connect( host="localhost", database="novadb", user="postgres", password="nova_db_pass" ) cursor = conn.cursor() cursor.execute("SELECT version();") version = cursor.fetchone() print(f"✅ PostgreSQL: Connected successfully - {version[0]}") conn.close() return True except Exception as e: print(f"❌ PostgreSQL: Connection failed - {e}") return False def test_mongodb(): """Test MongoDB connection""" try: client = pymongo.MongoClient("mongodb://localhost:27017/") db = client["nova_documents"] # Test connection by listing collections collections = db.list_collection_names() print(f"✅ MongoDB: Connected successfully - Collections: {len(collections)}") return True except Exception as e: print(f"❌ MongoDB: Connection failed - {e}") return False def test_chromadb(): """Test ChromaDB connection""" try: client = chromadb.PersistentClient(path="/data/chromadb") collections = client.list_collections() print(f"✅ ChromaDB: Connected successfully - Collections: {len(collections)}") return True except Exception as e: print(f"❌ ChromaDB: Connection failed - {e}") return False def test_qdrant(): """Test Qdrant connection""" try: client = qdrant_client.QdrantClient( host="localhost", port=17000, prefer_grpc=False ) collections = client.get_collections() print(f"✅ Qdrant: Connected successfully - Collections: {len(collections.collections)}") return True except Exception as e: print(f"❌ Qdrant: Connection failed - {e}") return False def test_dragonfly(): """Test DragonFly connection""" try: client = redis.Redis(host='localhost', port=18000, decode_responses=True) client.ping() print("✅ DragonFly: Connected successfully") return True except Exception as e: print(f"❌ DragonFly: Connection failed - {e}") return False def main(): """Main test function""" print("🔍 Testing Elizabeth DataOps Database Connections") print("=" * 60) results = {} # Test all databases results["redis"] = test_redis() results["postgresql"] = test_postgresql() results["mongodb"] = test_mongodb() results["chromadb"] = test_chromadb() results["qdrant"] = test_qdrant() results["dragonfly"] = test_dragonfly() print("=" * 60) # Summary successful = sum(results.values()) total = len(results) print(f"📊 Connection Summary: {successful}/{total} successful") if successful == total: print("🎉 All DataOps databases connected successfully!") print("Elizabeth can now utilize the complete infrastructure.") else: print("⚠️ Some connections failed. Elizabeth will use available databases.") return all(results.values()) if __name__ == "__main__": success = main() sys.exit(0 if success else 1)