|
18 | 18 | • tools/list (with stubbed service + DB)
|
19 | 19 | * handle_initialize_logic success, and both error branches
|
20 | 20 |
|
21 |
| -Now includes comprehensive backend testing, error scenarios, and cleanup tasks. |
| 21 | +
|
| 22 | +Includes comprehensive backend testing, error scenarios, and cleanup tasks. |
22 | 23 | """
|
23 | 24 |
|
24 | 25 | # Future
|
@@ -570,13 +571,17 @@ async def test_redis_session_operations(monkeypatch):
|
570 | 571 | """Test Redis backend session operations."""
|
571 | 572 | mock_redis = MockRedis()
|
572 | 573 |
|
573 |
| - # Patch Redis imports |
| 574 | + # Patch Redis imports before creating the registry |
574 | 575 | monkeypatch.setattr("mcpgateway.cache.session_registry.REDIS_AVAILABLE", True)
|
575 | 576 |
|
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 |
579 | 582 |
|
| 583 | + # Patch the Redis class import |
| 584 | + with patch("mcpgateway.cache.session_registry.Redis", MockRedisClass): |
580 | 585 | registry = SessionRegistry(backend="redis", redis_url="redis://localhost:6379")
|
581 | 586 | await registry.initialize()
|
582 | 587 |
|
@@ -615,9 +620,13 @@ async def test_redis_error_handling(monkeypatch):
|
615 | 620 |
|
616 | 621 | monkeypatch.setattr("mcpgateway.cache.session_registry.REDIS_AVAILABLE", True)
|
617 | 622 |
|
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 |
620 | 628 |
|
| 629 | + with patch("mcpgateway.cache.session_registry.Redis", MockRedisClass): |
621 | 630 | registry = SessionRegistry(backend="redis", redis_url="redis://localhost:6379")
|
622 | 631 | await registry.initialize()
|
623 | 632 |
|
|
0 commit comments