33ba453793
ISSUES CLOSED: #2
130 lines
5.1 KiB
Python
130 lines
5.1 KiB
Python
"""
|
|
Exceptions Tests
|
|
==============
|
|
|
|
This module contains tests for the custom exceptions in the AWS Storage Framework.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from clevercloud_storage_framework.exceptions import (
|
|
StorageError, InvalidPathError, OperationNotSupportedError,
|
|
AuthenticationError, ResourceNotFoundError, StoragePermissionError,
|
|
UnsupportedError
|
|
)
|
|
|
|
|
|
class TestExceptions:
|
|
"""Tests for the custom exceptions."""
|
|
|
|
def test_storage_error(self):
|
|
"""Test the StorageError exception."""
|
|
# Create an exception without a provider
|
|
error = StorageError("Test error")
|
|
assert str(error) == "Test error"
|
|
assert error.message == "Test error"
|
|
assert error.provider is None
|
|
|
|
# Create an exception with a provider
|
|
error = StorageError("Test error", provider="s3")
|
|
assert str(error) == "Test error (Provider: s3)"
|
|
assert error.message == "Test error"
|
|
assert error.provider == "s3"
|
|
|
|
def test_invalid_path_error(self):
|
|
"""Test the InvalidPathError exception."""
|
|
# Create an exception with default message
|
|
error = InvalidPathError("s3://bucket/key")
|
|
assert "Invalid path format: s3://bucket/key" in str(error)
|
|
assert error.path == "s3://bucket/key"
|
|
assert error.provider is None
|
|
|
|
# Create an exception with custom message and provider
|
|
error = InvalidPathError("s3://bucket/key", "Custom message", "s3")
|
|
assert "Custom message" in str(error)
|
|
assert error.path == "s3://bucket/key"
|
|
assert error.provider == "s3"
|
|
|
|
def test_operation_not_supported_error(self):
|
|
"""Test the OperationNotSupportedError exception."""
|
|
# Create an exception without a provider
|
|
error = OperationNotSupportedError("copy")
|
|
assert "Operation not supported: copy" in str(error)
|
|
assert error.operation == "copy"
|
|
assert error.provider is None
|
|
|
|
# Create an exception with a provider
|
|
error = OperationNotSupportedError("copy", "s3")
|
|
assert "Operation not supported: copy" in str(error)
|
|
assert error.operation == "copy"
|
|
assert error.provider == "s3"
|
|
|
|
def test_authentication_error(self):
|
|
"""Test the AuthenticationError exception."""
|
|
# Create an exception with default message
|
|
error = AuthenticationError()
|
|
assert "Authentication failed" in str(error)
|
|
assert error.provider is None
|
|
|
|
# Create an exception with custom message and provider
|
|
error = AuthenticationError("Invalid credentials", "s3")
|
|
assert "Invalid credentials" in str(error)
|
|
assert error.provider == "s3"
|
|
|
|
def test_resource_not_found_error(self):
|
|
"""Test the ResourceNotFoundError exception."""
|
|
# Create an exception without a provider
|
|
error = ResourceNotFoundError("s3://bucket/key")
|
|
assert "Resource not found: s3://bucket/key" in str(error)
|
|
assert error.resource == "s3://bucket/key"
|
|
assert error.provider is None
|
|
|
|
# Create an exception with a provider
|
|
error = ResourceNotFoundError("s3://bucket/key", "s3")
|
|
assert "Resource not found: s3://bucket/key" in str(error)
|
|
assert error.resource == "s3://bucket/key"
|
|
assert error.provider == "s3"
|
|
|
|
def test_permission_error(self):
|
|
"""Test the StoragePermissionError exception."""
|
|
# Create an exception with default message
|
|
error = StoragePermissionError()
|
|
assert "Permission denied" in str(error)
|
|
assert error.resource is None
|
|
assert error.provider is None
|
|
|
|
# Create an exception with resource
|
|
error = StoragePermissionError("s3://bucket/key")
|
|
assert "Permission denied for resource: s3://bucket/key" in str(error)
|
|
assert error.resource == "s3://bucket/key"
|
|
assert error.provider is None
|
|
|
|
# Create an exception with custom message and provider
|
|
error = StoragePermissionError("s3://bucket/key", "Custom message", "s3")
|
|
assert "Custom message" in str(error)
|
|
assert error.resource == "s3://bucket/key"
|
|
assert error.provider == "s3"
|
|
|
|
# Create an exception with message but no resource
|
|
error = StoragePermissionError(message="Custom message only")
|
|
assert "Custom message only" in str(error)
|
|
assert error.resource is None
|
|
assert error.provider is None
|
|
|
|
def test_unsupported_error(self):
|
|
"""Test the UnsupportedError exception."""
|
|
# Create an exception with default message
|
|
error = UnsupportedError()
|
|
assert "Unsupported feature requested" in str(error)
|
|
assert error.provider is None
|
|
|
|
# Create an exception with custom message
|
|
error = UnsupportedError("Pre-signed URLs not supported")
|
|
assert "Pre-signed URLs not supported" in str(error)
|
|
assert error.provider is None
|
|
|
|
# Create an exception with custom message and provider
|
|
error = UnsupportedError("Pre-signed URLs not supported", "efs")
|
|
assert "Pre-signed URLs not supported" in str(error)
|
|
assert error.provider == "efs"
|