You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.7 KiB
78 lines
2.7 KiB
"""
|
|
Integration tests for the complete RAG pipeline
|
|
"""
|
|
import pytest
|
|
import tempfile
|
|
import os
|
|
from unittest.mock import patch, Mock
|
|
import pandas as pd
|
|
|
|
|
|
class TestRAGPipelineIntegration:
|
|
"""Integration tests for complete RAG pipeline"""
|
|
|
|
@pytest.fixture
|
|
def temp_excel_file(self, sample_hadith_data):
|
|
"""Create temporary Excel file for testing"""
|
|
df = pd.DataFrame([sample_hadith_data])
|
|
|
|
with tempfile.NamedTemporaryFile(suffix='.xlsx', delete=False) as tmp:
|
|
df.to_excel(tmp.name, index=False)
|
|
yield tmp.name
|
|
|
|
# Cleanup
|
|
os.unlink(tmp.name)
|
|
|
|
@patch('src.knowledge.vector_store.get_qdrant_store')
|
|
def test_full_ingestion_pipeline(self, mock_get_qdrant, temp_excel_file):
|
|
"""Test full data ingestion pipeline"""
|
|
# Mock vector store
|
|
mock_vector_db = Mock()
|
|
mock_get_qdrant.return_value = mock_vector_db
|
|
|
|
# Mock knowledge base
|
|
with patch('src.knowledge.rag_pipeline.Knowledge') as mock_kb_class:
|
|
mock_kb_instance = Mock()
|
|
mock_kb_class.return_value = mock_kb_instance
|
|
|
|
# Import and run ingestion
|
|
from src.knowledge.rag_pipeline import create_knowledge_base, ingest_excel_data
|
|
|
|
# Create knowledge base
|
|
kb = create_knowledge_base(vector_store_type="qdrant")
|
|
|
|
# Ingest data
|
|
count = ingest_excel_data(kb, temp_excel_file, "hadiths")
|
|
|
|
# Verify calls
|
|
mock_get_qdrant.assert_called_once()
|
|
mock_kb_class.assert_called_once_with(vector_db=mock_vector_db)
|
|
assert count == 1
|
|
mock_kb_instance.add_content.assert_called_once()
|
|
|
|
@patch('src.agents.islamic_scholar_agent.IslamicScholarAgent')
|
|
@patch('src.models.openai.OpenAILikeModel')
|
|
@patch('src.knowledge.rag_pipeline.create_knowledge_base')
|
|
def test_agent_with_knowledge_base(self, mock_create_kb, mock_model_class, mock_agent_class):
|
|
"""Test agent initialization with knowledge base"""
|
|
# Setup mocks
|
|
mock_model_instance = Mock()
|
|
mock_model_instance.get_model.return_value = Mock()
|
|
mock_model_class.return_value = mock_model_instance
|
|
|
|
mock_kb = Mock()
|
|
mock_create_kb.return_value = mock_kb
|
|
|
|
mock_agent_instance = Mock()
|
|
mock_agent_class.return_value = mock_agent_instance
|
|
|
|
# Import and create agent
|
|
from src.agents.islamic_scholar_agent import IslamicScholarAgent
|
|
|
|
agent = IslamicScholarAgent(mock_model_instance.get_model(), mock_kb)
|
|
|
|
# Verify initialization
|
|
mock_agent_class.assert_called_once_with(
|
|
mock_model_instance.get_model(),
|
|
mock_kb
|
|
)
|