File tree Expand file tree Collapse file tree 5 files changed +15
-11
lines changed Expand file tree Collapse file tree 5 files changed +15
-11
lines changed Original file line number Diff line number Diff 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 ):
Original file line number Diff line number Diff line change 1111
1212class 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 :
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 4444 },
4545]
4646
47- USE_L10N = True
47+ USE_TZ = True
4848
4949AWS_ACCESS_KEY_ID = "testaccessid"
5050AWS_SECRET_ACCESS_KEY = "supersecretkey"
You can’t perform that action at this time.
0 commit comments