Skip to content

Commit 9846a80

Browse files
committed
Fix failing tests
1 parent 5c0f733 commit 9846a80

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

s3file/middleware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def get_files_from_storage(paths):
2929
for path in paths:
3030
path = pathlib.PurePosixPath(path)
3131
try:
32-
f = storage.open(str(path.relative_to(storage.location)))
32+
location = storage.aws_location
33+
except AttributeError:
34+
location = storage.location
35+
try:
36+
f = storage.open(str(path.relative_to(location)))
3337
f.name = path.name
3438
yield f
3539
except (OSError, ValueError):

s3file/storages.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
class S3MockStorage(FileSystemStorage):
1313
@property
14-
def location(self):
14+
def aws_location(self):
1515
return getattr(settings, "AWS_LOCATION", "")
1616

17-
def path(self, name):
18-
return safe_join(os.path.abspath(self.base_location), self.location, name)
17+
@property
18+
def location(self):
19+
return safe_join(os.path.abspath(self.base_location), self.aws_location)
1920

2021
class connection:
2122
class meta:

tests/test_forms.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ def freeze(self, monkeypatch):
3636
"""Freeze datetime and UUID."""
3737
monkeypatch.setattr(
3838
"s3file.forms.S3FileInputMixin.upload_folder",
39-
os.path.join(storage.location, "tmp"),
39+
os.path.join(storage.aws_location, "tmp"),
4040
)
4141

4242
def test_value_from_datadict(self, client, upload_file):
43+
print(storage.location)
4344
with open(upload_file) as f:
4445
uploaded_file = storage.save("test.jpg", f)
4546
response = client.post(
@@ -227,7 +228,5 @@ def test_media(self):
227228
assert ClearableFileInput().media._js == ["s3file/js/s3file.js"]
228229

229230
def test_upload_folder(self):
230-
assert ClearableFileInput().upload_folder.startswith(
231-
"custom/location/tmp/s3file/"
232-
)
233-
assert len(ClearableFileInput().upload_folder) == 49
231+
assert "custom/location/tmp/s3file/" in ClearableFileInput().upload_folder
232+
assert len(os.path.basename(ClearableFileInput().upload_folder)) == 22

tests/test_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_get_files_from_storage(self):
1414
"tmp/s3file/test_get_files_from_storage", ContentFile(content)
1515
)
1616
files = S3FileMiddleware.get_files_from_storage(
17-
[os.path.join(storage.location, name)]
17+
[os.path.join(storage.aws_location, name)]
1818
)
1919
file = next(files)
2020
assert file.read() == content

tests/testapp/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
]
4646

47-
USE_L10N = True
47+
USE_TZ = True
4848

4949
AWS_ACCESS_KEY_ID = "testaccessid"
5050
AWS_SECRET_ACCESS_KEY = "supersecretkey"

0 commit comments

Comments
 (0)