mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
- Implement ElasticsearchClient with full sync/async operations - Add ElasticsearchConfig with connection and embedding options - Create factory pattern following ChromaDB/Qdrant conventions - Add comprehensive test suite with 26 passing tests (100% coverage) - Support both sync and async Elasticsearch operations - Include proper error handling and edge case coverage - Update type system and factory to support Elasticsearch provider - Follow existing RAG patterns for consistency Resolves #3404 Co-Authored-By: João <joao@crewai.com>
77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
"""Tests for RAG config factory."""
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
|
|
from crewai.rag.factory import create_client
|
|
|
|
|
|
def test_create_client_chromadb():
|
|
"""Test ChromaDB client creation."""
|
|
mock_config = Mock()
|
|
mock_config.provider = "chromadb"
|
|
|
|
with patch("crewai.rag.factory.require") as mock_require:
|
|
mock_module = Mock()
|
|
mock_client = Mock()
|
|
mock_module.create_client.return_value = mock_client
|
|
mock_require.return_value = mock_module
|
|
|
|
result = create_client(mock_config)
|
|
|
|
assert result == mock_client
|
|
mock_require.assert_called_once_with(
|
|
"crewai.rag.chromadb.factory", purpose="The 'chromadb' provider"
|
|
)
|
|
mock_module.create_client.assert_called_once_with(mock_config)
|
|
|
|
|
|
def test_create_client_qdrant():
|
|
"""Test Qdrant client creation."""
|
|
mock_config = Mock()
|
|
mock_config.provider = "qdrant"
|
|
|
|
with patch("crewai.rag.factory.require") as mock_require:
|
|
mock_module = Mock()
|
|
mock_client = Mock()
|
|
mock_module.create_client.return_value = mock_client
|
|
mock_require.return_value = mock_module
|
|
|
|
result = create_client(mock_config)
|
|
|
|
assert result == mock_client
|
|
mock_require.assert_called_once_with(
|
|
"crewai.rag.qdrant.factory", purpose="The 'qdrant' provider"
|
|
)
|
|
mock_module.create_client.assert_called_once_with(mock_config)
|
|
|
|
|
|
def test_create_client_elasticsearch():
|
|
"""Test Elasticsearch client creation."""
|
|
mock_config = Mock()
|
|
mock_config.provider = "elasticsearch"
|
|
|
|
with patch("crewai.rag.factory.require") as mock_require:
|
|
mock_module = Mock()
|
|
mock_client = Mock()
|
|
mock_module.create_client.return_value = mock_client
|
|
mock_require.return_value = mock_module
|
|
|
|
result = create_client(mock_config)
|
|
|
|
assert result == mock_client
|
|
mock_require.assert_called_once_with(
|
|
"crewai.rag.elasticsearch.factory", purpose="The 'elasticsearch' provider"
|
|
)
|
|
mock_module.create_client.assert_called_once_with(mock_config)
|
|
|
|
|
|
def test_create_client_unsupported_provider():
|
|
"""Test that unsupported provider raises ValueError."""
|
|
mock_config = Mock()
|
|
mock_config.provider = "unsupported"
|
|
|
|
with pytest.raises(ValueError, match="Unsupported provider: unsupported"):
|
|
create_client(mock_config)
|