style: Format all Python files with ruff
- Formatted 103 files to comply with ruff format requirements - No code logic changes, only formatting/whitespace - Fixes CI formatting check failures
This commit is contained in:
@@ -20,18 +20,21 @@ from skill_seekers.cli.storage import (
|
||||
# Check if cloud storage dependencies are available
|
||||
try:
|
||||
import boto3 # noqa: F401
|
||||
|
||||
BOTO3_AVAILABLE = True
|
||||
except ImportError:
|
||||
BOTO3_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from google.cloud import storage # noqa: F401
|
||||
|
||||
GCS_AVAILABLE = True
|
||||
except ImportError:
|
||||
GCS_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from azure.storage.blob import BlobServiceClient # noqa: F401
|
||||
|
||||
AZURE_AVAILABLE = True
|
||||
except ImportError:
|
||||
AZURE_AVAILABLE = False
|
||||
@@ -41,12 +44,13 @@ except ImportError:
|
||||
# Factory Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_get_storage_adaptor_s3():
|
||||
"""Test S3 adaptor factory."""
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3'):
|
||||
adaptor = get_storage_adaptor('s3', bucket='test-bucket')
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3"):
|
||||
adaptor = get_storage_adaptor("s3", bucket="test-bucket")
|
||||
assert isinstance(adaptor, S3StorageAdaptor)
|
||||
|
||||
|
||||
@@ -54,8 +58,8 @@ def test_get_storage_adaptor_gcs():
|
||||
"""Test GCS adaptor factory."""
|
||||
if not GCS_AVAILABLE:
|
||||
pytest.skip("google-cloud-storage not installed")
|
||||
with patch('skill_seekers.cli.storage.gcs_storage.storage'):
|
||||
adaptor = get_storage_adaptor('gcs', bucket='test-bucket')
|
||||
with patch("skill_seekers.cli.storage.gcs_storage.storage"):
|
||||
adaptor = get_storage_adaptor("gcs", bucket="test-bucket")
|
||||
assert isinstance(adaptor, GCSStorageAdaptor)
|
||||
|
||||
|
||||
@@ -63,11 +67,11 @@ def test_get_storage_adaptor_azure():
|
||||
"""Test Azure adaptor factory."""
|
||||
if not AZURE_AVAILABLE:
|
||||
pytest.skip("azure-storage-blob not installed")
|
||||
with patch('skill_seekers.cli.storage.azure_storage.BlobServiceClient'):
|
||||
with patch("skill_seekers.cli.storage.azure_storage.BlobServiceClient"):
|
||||
adaptor = get_storage_adaptor(
|
||||
'azure',
|
||||
container='test-container',
|
||||
connection_string='DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key'
|
||||
"azure",
|
||||
container="test-container",
|
||||
connection_string="DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key",
|
||||
)
|
||||
assert isinstance(adaptor, AzureStorageAdaptor)
|
||||
|
||||
@@ -75,36 +79,37 @@ def test_get_storage_adaptor_azure():
|
||||
def test_get_storage_adaptor_invalid_provider():
|
||||
"""Test invalid provider raises error."""
|
||||
with pytest.raises(ValueError, match="Unsupported storage provider"):
|
||||
get_storage_adaptor('invalid', bucket='test')
|
||||
get_storage_adaptor("invalid", bucket="test")
|
||||
|
||||
|
||||
# ========================================
|
||||
# S3 Storage Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_s3_upload_file():
|
||||
"""Test S3 file upload."""
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Create temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||
tmp_file.write(b'test content')
|
||||
tmp_file.write(b"test content")
|
||||
tmp_path = tmp_file.name
|
||||
|
||||
try:
|
||||
# Test upload
|
||||
result = adaptor.upload_file(tmp_path, 'test.txt')
|
||||
result = adaptor.upload_file(tmp_path, "test.txt")
|
||||
|
||||
assert result == 's3://test-bucket/test.txt'
|
||||
assert result == "s3://test-bucket/test.txt"
|
||||
mock_client.upload_file.assert_called_once()
|
||||
finally:
|
||||
Path(tmp_path).unlink()
|
||||
@@ -115,23 +120,21 @@ def test_s3_download_file():
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
local_path = os.path.join(tmp_dir, 'downloaded.txt')
|
||||
local_path = os.path.join(tmp_dir, "downloaded.txt")
|
||||
|
||||
# Test download
|
||||
adaptor.download_file('test.txt', local_path)
|
||||
adaptor.download_file("test.txt", local_path)
|
||||
|
||||
mock_client.download_file.assert_called_once_with(
|
||||
'test-bucket', 'test.txt', local_path
|
||||
)
|
||||
mock_client.download_file.assert_called_once_with("test-bucket", "test.txt", local_path)
|
||||
|
||||
|
||||
def test_s3_list_files():
|
||||
@@ -139,18 +142,18 @@ def test_s3_list_files():
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_paginator = Mock()
|
||||
mock_page_iterator = [
|
||||
{
|
||||
'Contents': [
|
||||
"Contents": [
|
||||
{
|
||||
'Key': 'file1.txt',
|
||||
'Size': 100,
|
||||
'LastModified': Mock(isoformat=lambda: '2024-01-01T00:00:00'),
|
||||
'ETag': '"abc123"'
|
||||
"Key": "file1.txt",
|
||||
"Size": 100,
|
||||
"LastModified": Mock(isoformat=lambda: "2024-01-01T00:00:00"),
|
||||
"ETag": '"abc123"',
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -161,15 +164,15 @@ def test_s3_list_files():
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Test list
|
||||
files = adaptor.list_files('prefix/')
|
||||
files = adaptor.list_files("prefix/")
|
||||
|
||||
assert len(files) == 1
|
||||
assert files[0].key == 'file1.txt'
|
||||
assert files[0].key == "file1.txt"
|
||||
assert files[0].size == 100
|
||||
assert files[0].etag == 'abc123'
|
||||
assert files[0].etag == "abc123"
|
||||
|
||||
|
||||
def test_s3_file_exists():
|
||||
@@ -177,17 +180,17 @@ def test_s3_file_exists():
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_client.head_object.return_value = {}
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Test exists
|
||||
assert adaptor.file_exists('test.txt') is True
|
||||
assert adaptor.file_exists("test.txt") is True
|
||||
|
||||
|
||||
def test_s3_get_file_url():
|
||||
@@ -195,19 +198,19 @@ def test_s3_get_file_url():
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_client.generate_presigned_url.return_value = 'https://s3.amazonaws.com/signed-url'
|
||||
mock_client.generate_presigned_url.return_value = "https://s3.amazonaws.com/signed-url"
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Test URL generation
|
||||
url = adaptor.get_file_url('test.txt', expires_in=7200)
|
||||
url = adaptor.get_file_url("test.txt", expires_in=7200)
|
||||
|
||||
assert url == 'https://s3.amazonaws.com/signed-url'
|
||||
assert url == "https://s3.amazonaws.com/signed-url"
|
||||
mock_client.generate_presigned_url.assert_called_once()
|
||||
|
||||
|
||||
@@ -215,12 +218,13 @@ def test_s3_get_file_url():
|
||||
# GCS Storage Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_gcs_upload_file():
|
||||
"""Test GCS file upload."""
|
||||
if not GCS_AVAILABLE:
|
||||
pytest.skip("google-cloud-storage not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.gcs_storage.storage') as mock_storage:
|
||||
with patch("skill_seekers.cli.storage.gcs_storage.storage") as mock_storage:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_bucket = Mock()
|
||||
@@ -230,18 +234,18 @@ def test_gcs_upload_file():
|
||||
mock_bucket.blob.return_value = mock_blob
|
||||
mock_storage.Client.return_value = mock_client
|
||||
|
||||
adaptor = GCSStorageAdaptor(bucket='test-bucket')
|
||||
adaptor = GCSStorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Create temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||
tmp_file.write(b'test content')
|
||||
tmp_file.write(b"test content")
|
||||
tmp_path = tmp_file.name
|
||||
|
||||
try:
|
||||
# Test upload
|
||||
result = adaptor.upload_file(tmp_path, 'test.txt')
|
||||
result = adaptor.upload_file(tmp_path, "test.txt")
|
||||
|
||||
assert result == 'gs://test-bucket/test.txt'
|
||||
assert result == "gs://test-bucket/test.txt"
|
||||
mock_blob.upload_from_filename.assert_called_once()
|
||||
finally:
|
||||
Path(tmp_path).unlink()
|
||||
@@ -252,7 +256,7 @@ def test_gcs_download_file():
|
||||
if not GCS_AVAILABLE:
|
||||
pytest.skip("google-cloud-storage not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.gcs_storage.storage') as mock_storage:
|
||||
with patch("skill_seekers.cli.storage.gcs_storage.storage") as mock_storage:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_bucket = Mock()
|
||||
@@ -262,13 +266,13 @@ def test_gcs_download_file():
|
||||
mock_bucket.blob.return_value = mock_blob
|
||||
mock_storage.Client.return_value = mock_client
|
||||
|
||||
adaptor = GCSStorageAdaptor(bucket='test-bucket')
|
||||
adaptor = GCSStorageAdaptor(bucket="test-bucket")
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
local_path = os.path.join(tmp_dir, 'downloaded.txt')
|
||||
local_path = os.path.join(tmp_dir, "downloaded.txt")
|
||||
|
||||
# Test download
|
||||
adaptor.download_file('test.txt', local_path)
|
||||
adaptor.download_file("test.txt", local_path)
|
||||
|
||||
mock_blob.download_to_filename.assert_called_once()
|
||||
|
||||
@@ -278,27 +282,27 @@ def test_gcs_list_files():
|
||||
if not GCS_AVAILABLE:
|
||||
pytest.skip("google-cloud-storage not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.gcs_storage.storage') as mock_storage:
|
||||
with patch("skill_seekers.cli.storage.gcs_storage.storage") as mock_storage:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_blob = Mock()
|
||||
mock_blob.name = 'file1.txt'
|
||||
mock_blob.name = "file1.txt"
|
||||
mock_blob.size = 100
|
||||
mock_blob.updated = Mock(isoformat=lambda: '2024-01-01T00:00:00')
|
||||
mock_blob.etag = 'abc123'
|
||||
mock_blob.updated = Mock(isoformat=lambda: "2024-01-01T00:00:00")
|
||||
mock_blob.etag = "abc123"
|
||||
mock_blob.metadata = {}
|
||||
|
||||
mock_client.list_blobs.return_value = [mock_blob]
|
||||
mock_storage.Client.return_value = mock_client
|
||||
mock_client.bucket.return_value = Mock()
|
||||
|
||||
adaptor = GCSStorageAdaptor(bucket='test-bucket')
|
||||
adaptor = GCSStorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Test list
|
||||
files = adaptor.list_files('prefix/')
|
||||
files = adaptor.list_files("prefix/")
|
||||
|
||||
assert len(files) == 1
|
||||
assert files[0].key == 'file1.txt'
|
||||
assert files[0].key == "file1.txt"
|
||||
assert files[0].size == 100
|
||||
|
||||
|
||||
@@ -306,12 +310,13 @@ def test_gcs_list_files():
|
||||
# Azure Storage Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_azure_upload_file():
|
||||
"""Test Azure file upload."""
|
||||
if not AZURE_AVAILABLE:
|
||||
pytest.skip("azure-storage-blob not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.azure_storage.BlobServiceClient') as mock_blob_service:
|
||||
with patch("skill_seekers.cli.storage.azure_storage.BlobServiceClient") as mock_blob_service:
|
||||
# Setup mocks
|
||||
mock_service_client = Mock()
|
||||
mock_container_client = Mock()
|
||||
@@ -321,19 +326,21 @@ def test_azure_upload_file():
|
||||
mock_container_client.get_blob_client.return_value = mock_blob_client
|
||||
mock_blob_service.from_connection_string.return_value = mock_service_client
|
||||
|
||||
connection_string = 'DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key'
|
||||
adaptor = AzureStorageAdaptor(container='test-container', connection_string=connection_string)
|
||||
connection_string = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key"
|
||||
adaptor = AzureStorageAdaptor(
|
||||
container="test-container", connection_string=connection_string
|
||||
)
|
||||
|
||||
# Create temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
||||
tmp_file.write(b'test content')
|
||||
tmp_file.write(b"test content")
|
||||
tmp_path = tmp_file.name
|
||||
|
||||
try:
|
||||
# Test upload
|
||||
result = adaptor.upload_file(tmp_path, 'test.txt')
|
||||
result = adaptor.upload_file(tmp_path, "test.txt")
|
||||
|
||||
assert 'test.blob.core.windows.net' in result
|
||||
assert "test.blob.core.windows.net" in result
|
||||
mock_blob_client.upload_blob.assert_called_once()
|
||||
finally:
|
||||
Path(tmp_path).unlink()
|
||||
@@ -344,30 +351,32 @@ def test_azure_download_file():
|
||||
if not AZURE_AVAILABLE:
|
||||
pytest.skip("azure-storage-blob not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.azure_storage.BlobServiceClient') as mock_blob_service:
|
||||
with patch("skill_seekers.cli.storage.azure_storage.BlobServiceClient") as mock_blob_service:
|
||||
# Setup mocks
|
||||
mock_service_client = Mock()
|
||||
mock_container_client = Mock()
|
||||
mock_blob_client = Mock()
|
||||
mock_download_stream = Mock()
|
||||
mock_download_stream.readall.return_value = b'test content'
|
||||
mock_download_stream.readall.return_value = b"test content"
|
||||
|
||||
mock_service_client.get_container_client.return_value = mock_container_client
|
||||
mock_container_client.get_blob_client.return_value = mock_blob_client
|
||||
mock_blob_client.download_blob.return_value = mock_download_stream
|
||||
mock_blob_service.from_connection_string.return_value = mock_service_client
|
||||
|
||||
connection_string = 'DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key'
|
||||
adaptor = AzureStorageAdaptor(container='test-container', connection_string=connection_string)
|
||||
connection_string = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key"
|
||||
adaptor = AzureStorageAdaptor(
|
||||
container="test-container", connection_string=connection_string
|
||||
)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
local_path = os.path.join(tmp_dir, 'downloaded.txt')
|
||||
local_path = os.path.join(tmp_dir, "downloaded.txt")
|
||||
|
||||
# Test download
|
||||
adaptor.download_file('test.txt', local_path)
|
||||
adaptor.download_file("test.txt", local_path)
|
||||
|
||||
assert Path(local_path).exists()
|
||||
assert Path(local_path).read_bytes() == b'test content'
|
||||
assert Path(local_path).read_bytes() == b"test content"
|
||||
|
||||
|
||||
def test_azure_list_files():
|
||||
@@ -375,29 +384,31 @@ def test_azure_list_files():
|
||||
if not AZURE_AVAILABLE:
|
||||
pytest.skip("azure-storage-blob not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.azure_storage.BlobServiceClient') as mock_blob_service:
|
||||
with patch("skill_seekers.cli.storage.azure_storage.BlobServiceClient") as mock_blob_service:
|
||||
# Setup mocks
|
||||
mock_service_client = Mock()
|
||||
mock_container_client = Mock()
|
||||
mock_blob = Mock()
|
||||
mock_blob.name = 'file1.txt'
|
||||
mock_blob.name = "file1.txt"
|
||||
mock_blob.size = 100
|
||||
mock_blob.last_modified = Mock(isoformat=lambda: '2024-01-01T00:00:00')
|
||||
mock_blob.etag = 'abc123'
|
||||
mock_blob.last_modified = Mock(isoformat=lambda: "2024-01-01T00:00:00")
|
||||
mock_blob.etag = "abc123"
|
||||
mock_blob.metadata = {}
|
||||
|
||||
mock_container_client.list_blobs.return_value = [mock_blob]
|
||||
mock_service_client.get_container_client.return_value = mock_container_client
|
||||
mock_blob_service.from_connection_string.return_value = mock_service_client
|
||||
|
||||
connection_string = 'DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key'
|
||||
adaptor = AzureStorageAdaptor(container='test-container', connection_string=connection_string)
|
||||
connection_string = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=key"
|
||||
adaptor = AzureStorageAdaptor(
|
||||
container="test-container", connection_string=connection_string
|
||||
)
|
||||
|
||||
# Test list
|
||||
files = adaptor.list_files('prefix/')
|
||||
files = adaptor.list_files("prefix/")
|
||||
|
||||
assert len(files) == 1
|
||||
assert files[0].key == 'file1.txt'
|
||||
assert files[0].key == "file1.txt"
|
||||
assert files[0].size == 100
|
||||
|
||||
|
||||
@@ -405,53 +416,55 @@ def test_azure_list_files():
|
||||
# Base Adaptor Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_storage_object():
|
||||
"""Test StorageObject dataclass."""
|
||||
obj = StorageObject(
|
||||
key='test.txt',
|
||||
key="test.txt",
|
||||
size=100,
|
||||
last_modified='2024-01-01T00:00:00',
|
||||
etag='abc123',
|
||||
metadata={'key': 'value'}
|
||||
last_modified="2024-01-01T00:00:00",
|
||||
etag="abc123",
|
||||
metadata={"key": "value"},
|
||||
)
|
||||
|
||||
assert obj.key == 'test.txt'
|
||||
assert obj.key == "test.txt"
|
||||
assert obj.size == 100
|
||||
assert obj.metadata == {'key': 'value'}
|
||||
assert obj.metadata == {"key": "value"}
|
||||
|
||||
|
||||
def test_base_adaptor_abstract():
|
||||
"""Test that BaseStorageAdaptor cannot be instantiated."""
|
||||
with pytest.raises(TypeError):
|
||||
BaseStorageAdaptor(bucket='test')
|
||||
BaseStorageAdaptor(bucket="test")
|
||||
|
||||
|
||||
# ========================================
|
||||
# Integration-style Tests
|
||||
# ========================================
|
||||
|
||||
|
||||
def test_upload_directory():
|
||||
"""Test directory upload."""
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
# Create temporary directory with files
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
(Path(tmp_dir) / 'file1.txt').write_text('content1')
|
||||
(Path(tmp_dir) / 'file2.txt').write_text('content2')
|
||||
(Path(tmp_dir) / 'subdir').mkdir()
|
||||
(Path(tmp_dir) / 'subdir' / 'file3.txt').write_text('content3')
|
||||
(Path(tmp_dir) / "file1.txt").write_text("content1")
|
||||
(Path(tmp_dir) / "file2.txt").write_text("content2")
|
||||
(Path(tmp_dir) / "subdir").mkdir()
|
||||
(Path(tmp_dir) / "subdir" / "file3.txt").write_text("content3")
|
||||
|
||||
# Test upload directory
|
||||
uploaded_files = adaptor.upload_directory(tmp_dir, 'skills/')
|
||||
uploaded_files = adaptor.upload_directory(tmp_dir, "skills/")
|
||||
|
||||
assert len(uploaded_files) == 3
|
||||
assert mock_client.upload_file.call_count == 3
|
||||
@@ -462,25 +475,25 @@ def test_download_directory():
|
||||
if not BOTO3_AVAILABLE:
|
||||
pytest.skip("boto3 not installed")
|
||||
|
||||
with patch('skill_seekers.cli.storage.s3_storage.boto3') as mock_boto3:
|
||||
with patch("skill_seekers.cli.storage.s3_storage.boto3") as mock_boto3:
|
||||
# Setup mocks
|
||||
mock_client = Mock()
|
||||
mock_paginator = Mock()
|
||||
mock_page_iterator = [
|
||||
{
|
||||
'Contents': [
|
||||
"Contents": [
|
||||
{
|
||||
'Key': 'skills/file1.txt',
|
||||
'Size': 100,
|
||||
'LastModified': Mock(isoformat=lambda: '2024-01-01T00:00:00'),
|
||||
'ETag': '"abc"'
|
||||
"Key": "skills/file1.txt",
|
||||
"Size": 100,
|
||||
"LastModified": Mock(isoformat=lambda: "2024-01-01T00:00:00"),
|
||||
"ETag": '"abc"',
|
||||
},
|
||||
{
|
||||
'Key': 'skills/file2.txt',
|
||||
'Size': 200,
|
||||
'LastModified': Mock(isoformat=lambda: '2024-01-01T00:00:00'),
|
||||
'ETag': '"def"'
|
||||
}
|
||||
"Key": "skills/file2.txt",
|
||||
"Size": 200,
|
||||
"LastModified": Mock(isoformat=lambda: "2024-01-01T00:00:00"),
|
||||
"ETag": '"def"',
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -490,11 +503,11 @@ def test_download_directory():
|
||||
mock_boto3.client.return_value = mock_client
|
||||
mock_boto3.resource.return_value = Mock()
|
||||
|
||||
adaptor = S3StorageAdaptor(bucket='test-bucket')
|
||||
adaptor = S3StorageAdaptor(bucket="test-bucket")
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Test download directory
|
||||
downloaded_files = adaptor.download_directory('skills/', tmp_dir)
|
||||
downloaded_files = adaptor.download_directory("skills/", tmp_dir)
|
||||
|
||||
assert len(downloaded_files) == 2
|
||||
assert mock_client.download_file.call_count == 2
|
||||
|
||||
Reference in New Issue
Block a user