ConstitutionAgent / tests /test_connections.py
Meshyboi's picture
Upload 53 files
0cd3dc5 verified
import sys
import os
import pytest
from groq import Groq
# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.config import settings
from services.neo4j import get_neo4j_driver
from qdrant_client import QdrantClient
def test_groq_connection():
"""Test validity of Groq API Key and Model"""
if not settings.GROQ_API_KEY:
pytest.fail("GROQ_API_KEY is not set in environment/config")
client = Groq(api_key=settings.GROQ_API_KEY)
try:
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Ping"}],
model=settings.GROQ_MODEL
)
assert chat_completion.choices[0].message.content is not None
print("\n✅ Groq Connection: SUCCESS")
except Exception as e:
pytest.fail(f"Groq Connection Failed: {e}")
def test_neo4j_connection():
"""Test Neo4j Database Connection"""
driver = get_neo4j_driver()
try:
driver.verify_connectivity()
print("\n✅ Neo4j Connection: SUCCESS")
except Exception as e:
pytest.fail(f"Neo4j Connection Failed: {e}")
finally:
driver.close()
def test_qdrant_connection():
"""Test Qdrant Database Connection"""
try:
client = QdrantClient(host=settings.QDRANT_HOST, port=settings.QDRANT_PORT)
collections = client.get_collections()
assert collections is not None
print("\n✅ Qdrant Connection: SUCCESS")
except Exception as e:
pytest.fail(f"Qdrant Connection Failed: {e}")
if __name__ == "__main__":
# Allow running directly for quick check
test_groq_connection()
test_neo4j_connection()
test_qdrant_connection()