File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
2
import os
3
3
4
- from botocore .exceptions import ClientError
5
4
from django .core .files .storage import default_storage
6
5
7
6
logger = logging .getLogger ('s3file' )
@@ -24,9 +23,9 @@ def __call__(self, request):
24
23
def get_files_from_storage (paths ):
25
24
"""Return S3 file where the name does not include the path."""
26
25
for path in paths :
27
- f = default_storage .open (path )
28
- f .name = os .path .basename (path )
29
26
try :
27
+ f = default_storage .open (path )
28
+ f .name = os .path .basename (path )
30
29
yield f
31
- except ClientError :
30
+ except OSError :
32
31
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):
26
26
S3FileMiddleware (lambda x : None )(request )
27
27
assert request .FILES .getlist ('file' )
28
28
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