Skip to content

Commit 6a7df36

Browse files
committed
Update session_registry tests now including redis
Signed-off-by: Mihai Criveti <[email protected]>
1 parent e38a80f commit 6a7df36

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/unit/mcpgateway/cache/test_session_registry.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
• tools/list (with stubbed service + DB)
1919
* handle_initialize_logic success, and both error branches
2020
21-
Now includes comprehensive backend testing, error scenarios, and cleanup tasks.
21+
22+
Includes comprehensive backend testing, error scenarios, and cleanup tasks.
2223
"""
2324

2425
# Future
@@ -570,13 +571,17 @@ async def test_redis_session_operations(monkeypatch):
570571
"""Test Redis backend session operations."""
571572
mock_redis = MockRedis()
572573

573-
# Patch Redis imports
574+
# Patch Redis imports before creating the registry
574575
monkeypatch.setattr("mcpgateway.cache.session_registry.REDIS_AVAILABLE", True)
575576

576-
# We need to patch the Redis class that gets imported in the module
577-
with patch("redis.asyncio.Redis") as mock_redis_class:
578-
mock_redis_class.from_url.return_value = mock_redis
577+
# Create a mock Redis class that returns our specific mock instance
578+
class MockRedisClass:
579+
@classmethod
580+
def from_url(cls, url):
581+
return mock_redis
579582

583+
# Patch the Redis class import
584+
with patch("mcpgateway.cache.session_registry.Redis", MockRedisClass):
580585
registry = SessionRegistry(backend="redis", redis_url="redis://localhost:6379")
581586
await registry.initialize()
582587

@@ -615,9 +620,13 @@ async def test_redis_error_handling(monkeypatch):
615620

616621
monkeypatch.setattr("mcpgateway.cache.session_registry.REDIS_AVAILABLE", True)
617622

618-
with patch("redis.asyncio.Redis") as mock_redis_class:
619-
mock_redis_class.from_url.return_value = mock_redis
623+
# Create a mock Redis class that returns our specific mock instance
624+
class MockRedisClass:
625+
@classmethod
626+
def from_url(cls, url):
627+
return mock_redis
620628

629+
with patch("mcpgateway.cache.session_registry.Redis", MockRedisClass):
621630
registry = SessionRegistry(backend="redis", redis_url="redis://localhost:6379")
622631
await registry.initialize()
623632

0 commit comments

Comments
 (0)