Skip to content

Commit b49acfc

Browse files
committed
File Storage Test: Added tests for file storage and refactored static file mounting
1 parent 643dff3 commit b49acfc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

ellar/core/files/storages/aws_s3.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
import urllib.parse
33
from io import BytesIO
44

5+
from ellar.core.files.storages.base import BaseStorage
6+
57
try:
68
import boto3
7-
except ImportError as im_ex: # pragma: no cover
8-
raise RuntimeError(
9-
"boto3 must be installed to use the 'S3AWSFileStorage' class."
10-
) from im_ex
11-
12-
from .base import BaseStorage
9+
except ImportError:
10+
boto3 = None
1311

1412

1513
class S3AWSFileStorage(BaseStorage): # pragma: no cover
@@ -29,6 +27,11 @@ def __init__(
2927
enable_cache_control: bool = False,
3028
public_link_expiration: int = 3600,
3129
) -> None:
30+
if not boto3:
31+
raise RuntimeError(
32+
"boto3 must be installed to use the 'S3AWSFileStorage' class. pip install boto3"
33+
)
34+
3235
self.bucket = self.get_aws_bucket(
3336
bucket=bucket,
3437
secret_key=secret_key,

tests/test_storage/test_aws.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
from ellar.core.files.storages.aws_s3 import S3AWSFileStorage
3+
4+
5+
def test_aws_storage_boto3_package_unavailable():
6+
with pytest.raises(RuntimeError):
7+
S3AWSFileStorage(
8+
bucket="ellar", access_key="none", secret_key="none", region="not necessary"
9+
)

0 commit comments

Comments
 (0)