78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
"""
|
|
Test suite for StorageClient delete_file method
|
|
===========================================
|
|
|
|
This module contains tests for the delete_file method of the StorageClient class,
|
|
particularly focusing on cross-provider functionality.
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from clevercloud_storage_framework.client import StorageClient
|
|
from clevercloud_storage_framework.exceptions import StorageError
|
|
|
|
|
|
class TestStorageClientDeleteFile:
|
|
"""Test suite for StorageClient delete_file method."""
|
|
|
|
@pytest.fixture
|
|
def mock_provider(self):
|
|
"""Create a mock storage provider."""
|
|
provider = MagicMock()
|
|
provider.get_provider_name.return_value = "mock"
|
|
provider.supports_path.return_value = True
|
|
return provider
|
|
|
|
@pytest.fixture
|
|
def client(self, mock_provider):
|
|
"""Create a StorageClient with a mock provider."""
|
|
return StorageClient(mock_provider)
|
|
|
|
def test_delete_file_with_supported_path(self, client, mock_provider):
|
|
"""Test deleting a file with a path supported by the current provider."""
|
|
# Setup
|
|
path = "mock://bucket/file.txt"
|
|
mock_provider.supports_path.return_value = True
|
|
|
|
# Execute
|
|
client.delete_file(path)
|
|
|
|
# Verify
|
|
mock_provider.delete_file.assert_called_once_with(path)
|
|
|
|
@patch('clevercloud_storage_framework.factory.StorageClientFactory.get_provider_for_path')
|
|
def test_delete_file_with_unsupported_path(self, mock_get_provider, client, mock_provider):
|
|
"""Test deleting a file with a path not supported by the current provider."""
|
|
# Setup
|
|
path = "s3://bucket/file.txt"
|
|
mock_provider.supports_path.return_value = False
|
|
|
|
# Create a mock S3 provider
|
|
mock_s3_provider = MagicMock()
|
|
mock_s3_provider.get_provider_name.return_value = "s3"
|
|
mock_get_provider.return_value = mock_s3_provider
|
|
|
|
# Execute
|
|
client.delete_file(path)
|
|
|
|
# Verify
|
|
mock_get_provider.assert_called_once_with(path)
|
|
mock_s3_provider.delete_file.assert_called_once_with(path)
|
|
mock_provider.delete_file.assert_not_called()
|
|
|
|
@patch('clevercloud_storage_framework.factory.StorageClientFactory.get_provider_for_path')
|
|
def test_delete_file_fallback_to_current_provider(self, mock_get_provider, client, mock_provider):
|
|
"""Test fallback to current provider when no suitable provider is found."""
|
|
# Setup
|
|
path = "unknown://bucket/file.txt"
|
|
mock_provider.supports_path.return_value = False
|
|
mock_get_provider.side_effect = StorageError("No provider found", provider="unknown")
|
|
|
|
# Execute
|
|
client.delete_file(path)
|
|
|
|
# Verify
|
|
mock_get_provider.assert_called_once_with(path)
|
|
mock_provider.delete_file.assert_called_once_with(path)
|