Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Mar 19, 2022
1 parent fbd4a45 commit cfe54df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion s3file/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def get_files_from_storage(paths):
for path in paths:
path = pathlib.PurePosixPath(path)
try:
f = storage.open(str(path.relative_to(storage.location)))
location = storage.aws_location
except AttributeError:
location = storage.location
try:
f = storage.open(str(path.relative_to(location)))
f.name = path.name
yield f
except (OSError, ValueError):
Expand Down
7 changes: 4 additions & 3 deletions s3file/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

class S3MockStorage(FileSystemStorage):
@property
def location(self):
def aws_location(self):
return getattr(settings, "AWS_LOCATION", "")

def path(self, name):
return safe_join(os.path.abspath(self.base_location), self.location, name)
@property
def location(self):
return safe_join(os.path.abspath(self.base_location), self.aws_location)

class connection:
class meta:
Expand Down
9 changes: 4 additions & 5 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def freeze(self, monkeypatch):
"""Freeze datetime and UUID."""
monkeypatch.setattr(
"s3file.forms.S3FileInputMixin.upload_folder",
os.path.join(storage.location, "tmp"),
os.path.join(storage.aws_location, "tmp"),
)

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

def test_upload_folder(self):
assert ClearableFileInput().upload_folder.startswith(
"custom/location/tmp/s3file/"
)
assert len(ClearableFileInput().upload_folder) == 49
assert "custom/location/tmp/s3file/" in ClearableFileInput().upload_folder
assert len(os.path.basename(ClearableFileInput().upload_folder)) == 22
2 changes: 1 addition & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_files_from_storage(self):
"tmp/s3file/test_get_files_from_storage", ContentFile(content)
)
files = S3FileMiddleware.get_files_from_storage(
[os.path.join(storage.location, name)]
[os.path.join(storage.aws_location, name)]
)
file = next(files)
assert file.read() == content
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
]

USE_L10N = True
USE_TZ = True

AWS_ACCESS_KEY_ID = "testaccessid"
AWS_SECRET_ACCESS_KEY = "supersecretkey"
Expand Down

0 comments on commit cfe54df

Please sign in to comment.