64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""
|
|
Unit tests for storage factory
|
|
Story 6.1 & 6.2: Storage Provider Abstraction and S3 Client
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock
|
|
|
|
from src.deployment.storage_factory import create_storage_client
|
|
from src.deployment.bunny_storage import BunnyStorageClient
|
|
from src.deployment.s3_storage import S3StorageClient
|
|
from src.database.models import SiteDeployment
|
|
|
|
|
|
class TestStorageFactory:
|
|
"""Test storage client factory"""
|
|
|
|
def test_create_bunny_client(self):
|
|
"""Test factory returns BunnyStorageClient for 'bunny' provider"""
|
|
site = Mock(spec=SiteDeployment)
|
|
site.storage_provider = 'bunny'
|
|
|
|
client = create_storage_client(site)
|
|
|
|
assert isinstance(client, BunnyStorageClient)
|
|
|
|
def test_create_bunny_client_default(self):
|
|
"""Test factory defaults to BunnyStorageClient when provider not set"""
|
|
site = Mock(spec=SiteDeployment)
|
|
# storage_provider not set
|
|
|
|
client = create_storage_client(site)
|
|
|
|
assert isinstance(client, BunnyStorageClient)
|
|
|
|
def test_create_s3_client(self):
|
|
"""Test factory returns S3StorageClient for 's3' provider"""
|
|
site = Mock(spec=SiteDeployment)
|
|
site.storage_provider = 's3'
|
|
|
|
client = create_storage_client(site)
|
|
|
|
assert isinstance(client, S3StorageClient)
|
|
|
|
def test_create_s3_compatible_client(self):
|
|
"""Test factory returns S3StorageClient for 's3_compatible' provider"""
|
|
site = Mock(spec=SiteDeployment)
|
|
site.storage_provider = 's3_compatible'
|
|
|
|
client = create_storage_client(site)
|
|
|
|
assert isinstance(client, S3StorageClient)
|
|
|
|
def test_create_unknown_provider(self):
|
|
"""Test factory raises ValueError for unknown provider"""
|
|
site = Mock(spec=SiteDeployment)
|
|
site.storage_provider = 'unknown_provider'
|
|
|
|
with pytest.raises(ValueError) as exc_info:
|
|
create_storage_client(site)
|
|
|
|
assert "Unknown storage provider" in str(exc_info.value)
|
|
|