"""Test cache_utils.""" from unittest.mock import patch import pytest from permissions.utils.cache_utils import bust_by_identity, get_resources_key @pytest.mark.parametrize( ('profile_type', 'profile_id', 'resource_type', 'expected'), [ ('pt', 'pid', 'rt', 'resources_for_pt_pid_rt'), ('pt', 'pid', None, 'resources_for_pt_pid_*'), ], ) def test_redis_get_resources_key(profile_type, profile_id, resource_type, expected): """Test all the redis client methods.""" result = get_resources_key(profile_type, profile_id, resource_type) assert result == expected @patch('permissions.utils.cache_utils.redis') def test_bust_by_identity(mock_redis): """Test bust_by_identity.""" mock_redis.delete_keys.return_value = True bust_by_identity( ['uuid1', 'uuid2'], ['all_admin', 'collaborators'], ) mock_redis.delete_keys.assert_called_with( [ 'resources_for_identity_uuid1_all_admin', 'resources_for_identity_uuid2_all_admin', 'resources_for_identity_uuid1_collaborators', 'resources_for_identity_uuid2_collaborators', ] )