11import json
2+ from unittest import mock
23
34import pytest
45from mcp .shared .memory import (
1213)
1314
1415
16+ @pytest .fixture
17+ async def mcp_test_setup (async_redis_client , search_index ):
18+ with (
19+ mock .patch (
20+ "agent_memory_server.long_term_memory.get_redis_conn" ,
21+ return_value = async_redis_client ,
22+ ) as _mock_ltm_redis ,
23+ mock .patch (
24+ "agent_memory_server.api.get_redis_conn" ,
25+ return_value = async_redis_client ,
26+ create = True ,
27+ ) as _mock_api_redis ,
28+ ):
29+ yield
30+
31+
1532class TestMCP :
1633 """Test search functionality and memory prompt endpoints via client sessions."""
1734
1835 @pytest .mark .asyncio
19- async def test_create_long_term_memory (self , session ):
36+ async def test_create_long_term_memory (self , session , mcp_test_setup ):
2037 async with client_session (mcp_app ._mcp_server ) as client :
2138 results = await client .call_tool (
2239 "create_long_term_memories" ,
@@ -31,7 +48,7 @@ async def test_create_long_term_memory(self, session):
3148 assert results .content [0 ].text == '{"status": "ok"}'
3249
3350 @pytest .mark .asyncio
34- async def test_search_memory (self , session ):
51+ async def test_search_memory (self , session , mcp_test_setup ):
3552 """Test searching through session memory using the client."""
3653 async with client_session (mcp_app ._mcp_server ) as client :
3754 results = await client .call_tool (
@@ -65,7 +82,7 @@ async def test_search_memory(self, session):
6582 assert results ["memories" ][1 ]["session_id" ] == session
6683
6784 @pytest .mark .asyncio
68- async def test_memory_prompt (self , session ):
85+ async def test_memory_prompt (self , session , mcp_test_setup ):
6986 """Test memory prompt with various parameter combinations."""
7087 async with client_session (mcp_app ._mcp_server ) as client :
7188 prompt = await client .call_tool (
@@ -98,7 +115,7 @@ async def test_memory_prompt(self, session):
98115 assert "assistant: Hi there" in message ["content" ]["text" ]
99116
100117 @pytest .mark .asyncio
101- async def test_memory_prompt_error_handling (self , session ):
118+ async def test_memory_prompt_error_handling (self , session , mcp_test_setup ):
102119 """Test error handling in memory prompt generation via the client."""
103120 async with client_session (mcp_app ._mcp_server ) as client :
104121 # Test with a non-existent session id
0 commit comments