83 lines
2.0 KiB
Python
83 lines
2.0 KiB
Python
"""
|
|
Pytest configuration and fixtures for chat-handler tests.
|
|
"""
|
|
|
|
import asyncio
|
|
import os
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
# Set test environment variables before importing
|
|
os.environ.setdefault("NATS_URL", "nats://localhost:4222")
|
|
os.environ.setdefault("REDIS_URL", "redis://localhost:6379")
|
|
os.environ.setdefault("MILVUS_HOST", "localhost")
|
|
os.environ.setdefault("OTEL_ENABLED", "false")
|
|
os.environ.setdefault("MLFLOW_ENABLED", "false")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop():
|
|
"""Create event loop for async tests."""
|
|
loop = asyncio.new_event_loop()
|
|
yield loop
|
|
loop.close()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_embedding():
|
|
"""Sample embedding vector."""
|
|
return [0.1] * 1024
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_documents():
|
|
"""Sample search results."""
|
|
return [
|
|
{"text": "Machine learning is a subset of AI.", "score": 0.95},
|
|
{"text": "Deep learning uses neural networks.", "score": 0.90},
|
|
{"text": "AI enables intelligent automation.", "score": 0.85},
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_reranked():
|
|
"""Sample reranked results."""
|
|
return [
|
|
{"document": "Machine learning is a subset of AI.", "score": 0.98},
|
|
{"document": "Deep learning uses neural networks.", "score": 0.85},
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_nats_message():
|
|
"""Create a mock NATS message."""
|
|
msg = MagicMock()
|
|
msg.subject = "ai.chat.request"
|
|
msg.reply = "ai.chat.response.test-123"
|
|
return msg
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_chat_request():
|
|
"""Sample chat request payload."""
|
|
return {
|
|
"request_id": "test-request-123",
|
|
"query": "What is machine learning?",
|
|
"collection": "test_collection",
|
|
"enable_tts": False,
|
|
"system_prompt": None,
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_chat_request_with_tts():
|
|
"""Sample chat request with TTS enabled."""
|
|
return {
|
|
"request_id": "test-request-456",
|
|
"query": "Tell me about AI",
|
|
"collection": "documents",
|
|
"enable_tts": True,
|
|
"system_prompt": "You are a helpful assistant.",
|
|
}
|