from unittest.mock import AsyncMock, MagicMock, patch import pytest from pydantic import ValidationError from pdp.cli.commands.redis import cache_bludgeon from pdp.constants.constants import CacheEntryType from pdp.fastapi.schemas.infra import BludgeonCacheRequest @patch("pdp.cli.commands.redis.cache_bludgeon_logic", new_callable=AsyncMock) @patch("pdp.cli.commands.redis.RedisConnector") def test_cache_bludgeon( mock_redis_connector: MagicMock, mock_cache_bludgeon: AsyncMock, ) -> None: """Test cache bludgeon command.""" cache_bludgeon(CacheEntryType.CACHE_ENTRY_IDENTITY_ALLOWED_TENANTS) mock_cache_bludgeon.assert_called_with( bludgeon_cache_request=BludgeonCacheRequest( cache_entry_type=CacheEntryType.CACHE_ENTRY_IDENTITY_ALLOWED_TENANTS, delete=True, ), redis_connector=mock_redis_connector(), ) @patch("pdp.cli.commands.redis.cache_bludgeon_logic", new_callable=AsyncMock) @patch("pdp.cli.commands.redis.RedisConnector") def test_cache_bludgeon_wrong_cache_entry_type( mock_redis_connector: MagicMock, mock_cache_bludgeon: AsyncMock, ) -> None: """Test cache bludgeon command with invalid cache entry type.""" with pytest.raises(ValidationError): cache_bludgeon("not a cache entry type") # type: ignore[arg-type] mock_cache_bludgeon.assert_not_called()