Use mock-reddis
This commit is contained in:
@@ -8,7 +8,7 @@ continuations.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -121,11 +121,27 @@ def helper_function():
|
||||
assert any(str(Path(f).resolve()) == expected_resolved for f in captured_files)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("utils.conversation_memory.get_redis_client")
|
||||
@patch("providers.ModelProviderRegistry.get_provider_for_model")
|
||||
async def test_conversation_continuation_with_directory_files(
|
||||
self, mock_get_provider, tool, temp_directory_with_files
|
||||
self, mock_get_provider, mock_redis, tool, temp_directory_with_files
|
||||
):
|
||||
"""Test that conversation continuation works correctly with directory expansion"""
|
||||
# Setup mock Redis client with in-memory storage
|
||||
mock_client = Mock()
|
||||
redis_storage = {} # Simulate Redis storage
|
||||
|
||||
def mock_get(key):
|
||||
return redis_storage.get(key)
|
||||
|
||||
def mock_setex(key, ttl, value):
|
||||
redis_storage[key] = value
|
||||
return True
|
||||
|
||||
mock_client.get.side_effect = mock_get
|
||||
mock_client.setex.side_effect = mock_setex
|
||||
mock_redis.return_value = mock_client
|
||||
|
||||
# Setup mock provider
|
||||
mock_provider = create_mock_provider()
|
||||
mock_get_provider.return_value = mock_provider
|
||||
@@ -180,8 +196,24 @@ def helper_function():
|
||||
# This test shows the fix is working - conversation continuation properly filters out
|
||||
# already-embedded files. The exact length depends on whether any new files are found.
|
||||
|
||||
def test_get_conversation_embedded_files_with_expanded_files(self, tool, temp_directory_with_files):
|
||||
@patch("utils.conversation_memory.get_redis_client")
|
||||
def test_get_conversation_embedded_files_with_expanded_files(self, mock_redis, tool, temp_directory_with_files):
|
||||
"""Test that get_conversation_embedded_files returns expanded files"""
|
||||
# Setup mock Redis client with in-memory storage
|
||||
mock_client = Mock()
|
||||
redis_storage = {} # Simulate Redis storage
|
||||
|
||||
def mock_get(key):
|
||||
return redis_storage.get(key)
|
||||
|
||||
def mock_setex(key, ttl, value):
|
||||
redis_storage[key] = value
|
||||
return True
|
||||
|
||||
mock_client.get.side_effect = mock_get
|
||||
mock_client.setex.side_effect = mock_setex
|
||||
mock_redis.return_value = mock_client
|
||||
|
||||
directory = temp_directory_with_files["directory"]
|
||||
expected_files = temp_directory_with_files["files"]
|
||||
|
||||
@@ -205,8 +237,24 @@ def helper_function():
|
||||
assert set(embedded_files) == set(expected_files)
|
||||
assert directory not in embedded_files
|
||||
|
||||
def test_file_filtering_with_mixed_files_and_directories(self, tool, temp_directory_with_files):
|
||||
@patch("utils.conversation_memory.get_redis_client")
|
||||
def test_file_filtering_with_mixed_files_and_directories(self, mock_redis, tool, temp_directory_with_files):
|
||||
"""Test file filtering when request contains both individual files and directories"""
|
||||
# Setup mock Redis client with in-memory storage
|
||||
mock_client = Mock()
|
||||
redis_storage = {} # Simulate Redis storage
|
||||
|
||||
def mock_get(key):
|
||||
return redis_storage.get(key)
|
||||
|
||||
def mock_setex(key, ttl, value):
|
||||
redis_storage[key] = value
|
||||
return True
|
||||
|
||||
mock_client.get.side_effect = mock_get
|
||||
mock_client.setex.side_effect = mock_setex
|
||||
mock_redis.return_value = mock_client
|
||||
|
||||
directory = temp_directory_with_files["directory"]
|
||||
python_file = temp_directory_with_files["python_file"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user