quivr/backend/modules/brain/service/test_brain_service.py
Stan Girard 652d2b32e2
fix: 🐛 brains (#2107)
selection now fixed

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2024-01-28 01:03:36 -08:00

35 lines
1.1 KiB
Python

from unittest.mock import Mock
from uuid import UUID
from modules.brain.entity.brain_entity import BrainEntity
from modules.brain.service.brain_service import BrainService
def test_find_brain_from_question_with_history_and_brain_id():
brain_service = BrainService()
user = Mock()
user.id = 1
chat_id = UUID("12345678123456781234567812345678")
question = "What is the meaning of life?"
brain_id = UUID("87654321876543218765432187654321")
history = [
{
"user_message": "What is AI?",
"brain_id": UUID("87654321876543218765432187654321"),
}
]
vector_store = Mock()
vector_store.find_brain_closest_query.return_value = []
brain_entity_mock = Mock(spec=BrainEntity) # Create a mock BrainEntity
brain_service.get_brain_by_id = Mock(
return_value=brain_entity_mock
) # Mock the get_brain_by_id method
brain_to_use, metadata = brain_service.find_brain_from_question(
brain_id, question, user, chat_id, history, vector_store
)
assert isinstance(brain_to_use, BrainEntity)
assert "close_brains" in metadata