-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): make S3 URL expiration customizable (#345)
* feat(storage): make S3 URL expiration customizable * feat(config): make URL expiration an env var * test(storage): add test cases * style(test): remove legacy import * fix(config): fix type casting
- Loading branch information
Showing
3 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
import io | ||
|
||
import pytest | ||
from httpx import AsyncClient | ||
|
||
from app.services.storage import S3Bucket, s3_bucket | ||
|
||
|
||
def test_s3_bucket(): | ||
@pytest.mark.asyncio | ||
async def test_s3_bucket(async_client: AsyncClient, mock_img: bytes): | ||
assert isinstance(s3_bucket, S3Bucket) | ||
bucket_key = "logo.png" | ||
url_expiration = 1 | ||
# Check the file does not exist | ||
assert not (await s3_bucket.check_file_existence(bucket_key)) | ||
assert await s3_bucket.upload_file(bucket_key, io.BytesIO(mock_img)) | ||
assert await s3_bucket.check_file_existence(bucket_key) | ||
assert isinstance(await s3_bucket.get_file_metadata(bucket_key), dict) | ||
# Get the public URL | ||
file_url = await s3_bucket.get_public_url(bucket_key, url_expiration) | ||
assert file_url.startswith("http://") | ||
# Check the file is deleted | ||
await s3_bucket.delete_file(bucket_key) | ||
assert not (await s3_bucket.check_file_existence(bucket_key)) |