File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 11import logging
22import os
33
4- from botocore .exceptions import ClientError
54from django .core .files .storage import default_storage
65
76logger = logging .getLogger ('s3file' )
@@ -24,9 +23,9 @@ def __call__(self, request):
2423 def get_files_from_storage (paths ):
2524 """Return S3 file where the name does not include the path."""
2625 for path in paths :
27- f = default_storage .open (path )
28- f .name = os .path .basename (path )
2926 try :
27+ f = default_storage .open (path )
28+ f .name = os .path .basename (path )
3029 yield f
31- except ClientError :
30+ except OSError :
3231 logger .exception ("File not found: %s" , path )
Original file line number Diff line number Diff line change @@ -26,3 +26,9 @@ def test_process_request(self, rf):
2626 S3FileMiddleware (lambda x : None )(request )
2727 assert request .FILES .getlist ('file' )
2828 assert request .FILES .get ('file' ).read () == b's3file'
29+
30+ def test_process_request__no_file (self , rf , caplog ):
31+ request = rf .post ('/' , data = {'file' : 'does_not_exist.txt' , 's3file' : 'file' })
32+ S3FileMiddleware (lambda x : None )(request )
33+ assert not request .FILES .getlist ('file' )
34+ assert 'File not found: does_not_exist.txt' in caplog .text
You can’t perform that action at this time.
0 commit comments