llama-stack-mirror/tests/unit/providers/files/test_remote_files_s3.py
Sébastien Han 1afd33c21e
wip
2025-05-14 10:13:17 +02:00

59 lines
1.6 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
from collections.abc import AsyncGenerator
import pytest
from llama_stack.providers.remote.files.object.s3.config import S3FilesImplConfig
from llama_stack.providers.remote.files.object.s3.s3_files import S3FilesAdapter
from llama_stack.providers.utils.kvstore import KVStore, kvstore_impl
from llama_stack.providers.utils.kvstore.config import SqliteKVStoreConfig
@pytest.fixture
def s3_config():
return S3FilesImplConfig(
aws_access_key_id="test-key",
aws_secret_access_key="test-secret",
region_name="us-east-1",
endpoint_url="http://localhost:9000",
)
@pytest.fixture
async def kvstore() -> AsyncGenerator[KVStore, None]:
"""Create a SQLite KV store for testing."""
config = SqliteKVStoreConfig(
path=":memory:" # Use in-memory SQLite for tests
)
store = await kvstore_impl(config)
await store.initialize()
yield store
@pytest.fixture
async def s3_files(s3_config, kvstore):
adapter = S3FilesAdapter(
s3_config,
kvstore,
)
await adapter.initialize()
return adapter
@pytest.mark.asyncio
async def test_create_upload_session(s3_files):
bucket = "test-bucket"
key = "test-file.txt"
mime_type = "text/plain"
size = 1024
response = await s3_files.create_upload_session(bucket, key, mime_type, size)
assert response.id == f"{bucket}/{key}"
assert response.size == size
assert response.offset == 0
assert response.url is not None