from typing import Any from mypy_boto3_dynamodb import DynamoDBClient from pdp.connectors.dynamo import DynamoDbConnector from pdp.connectors.redis_client import ( PydanticSchemaSerializer, RedisConnector, ) from pdp.constants.constants import CACHE_ENTRY_TENANT_HIERARCHY from pdp.fastapi.schemas.tenant import IdExchangeTenantHierarchy from tests.integration.utils import run_command async def test_cache_bludgeon_cli( default_boto_client: DynamoDBClient, local_dynamo_connector_with_range: DynamoDbConnector, local_redis_connector: RedisConnector, monkeypatch: Any, ) -> None: """Test the cache_bludgeon command.""" # Load data into redis. await local_redis_connector.mset( key_item_dict={ "tenant_hierarchy@tenant_id#123|tenant_type#account": IdExchangeTenantHierarchy( # noqa: E501 tenant_id="123", tenant_type="account", tenant_uuid="c07e0113-df8a-46be-851a-b0f0df868bf9", company_brand=None, ), "tenant_hierarchy@tenant_id#456|tenant_type#account": IdExchangeTenantHierarchy( # noqa: E501 tenant_id="456", tenant_type="account", tenant_uuid="7c7ac83d-5a69-4385-99ed-2a19d8567ff1", company_brand=None, ), }, serializer=PydanticSchemaSerializer(IdExchangeTenantHierarchy), ) result = await local_redis_connector.list(pattern="tenant_hierarchy@*") # Assert the data is in redis. result.sort() assert result == [ "tenant_hierarchy@tenant_id#123|tenant_type#account", "tenant_hierarchy@tenant_id#456|tenant_type#account", ] # Run the cache_bludgeon command. run_command( [ "uv", "run", "pdpcli", "redis", "cache_bludgeon", CACHE_ENTRY_TENANT_HIERARCHY, ] ) result_after_bludgeon = await local_redis_connector.list( pattern="tenant_hierarchy@*" ) # Assert that there is no longer tenant_hierarchy@* # keys in redis. assert result_after_bludgeon == []