3
3
from contextlib import contextmanager
4
4
5
5
import pytest
6
- from django .core .files .storage import default_storage
7
6
from django .forms import ClearableFileInput
8
7
from selenium .common .exceptions import NoSuchElementException
9
8
from selenium .webdriver .support .expected_conditions import staleness_of
10
9
from selenium .webdriver .support .wait import WebDriverWait
11
10
11
+ from s3file .storages import storage
12
12
from tests .testapp .forms import UploadForm
13
13
14
14
try :
@@ -35,11 +35,14 @@ def url(self):
35
35
@pytest .fixture
36
36
def freeze (self , monkeypatch ):
37
37
"""Freeze datetime and UUID."""
38
- monkeypatch .setattr ('s3file.forms.S3FileInputMixin.upload_folder' , 'tmp' )
38
+ monkeypatch .setattr (
39
+ 's3file.forms.S3FileInputMixin.upload_folder' ,
40
+ os .path .join (storage .location , 'tmp' ),
41
+ )
39
42
40
43
def test_value_from_datadict (self , client , upload_file ):
41
44
with open (upload_file ) as f :
42
- uploaded_file = default_storage .save ('test.jpg' , f )
45
+ uploaded_file = storage .save ('test.jpg' , f )
43
46
response = client .post (reverse ('upload' ), {
44
47
'file' : json .dumps ([uploaded_file ]),
45
48
's3file' : '["file"]' ,
@@ -96,7 +99,7 @@ def test_get_conditions(self, freeze):
96
99
assert all (condition in conditions for condition in [
97
100
{"bucket" : 'test-bucket' },
98
101
{"success_action_status" : "201" },
99
- ['starts-with' , '$key' , 'tmp' ],
102
+ ['starts-with' , '$key' , 'custom/location/ tmp' ],
100
103
["starts-with" , "$Content-Type" , "" ]
101
104
]), conditions
102
105
@@ -139,7 +142,7 @@ def test_file_insert(self, request, driver, live_server, upload_file, freeze):
139
142
assert file_input .get_attribute ('name' ) == 'file'
140
143
with wait_for_page_load (driver , timeout = 10 ):
141
144
file_input .submit ()
142
- assert default_storage .exists ('tmp/%s.txt' % request .node .name )
145
+ assert storage .exists ('tmp/%s.txt' % request .node .name )
143
146
144
147
with pytest .raises (NoSuchElementException ):
145
148
error = driver .find_element_by_xpath ('//body[@JSError]' )
@@ -208,5 +211,7 @@ def test_media(self):
208
211
assert ClearableFileInput ().media ._js == ['s3file/js/s3file.js' ]
209
212
210
213
def test_upload_folder (self ):
211
- assert ClearableFileInput ().upload_folder .startswith ('tmp/s3file/' )
212
- assert len (ClearableFileInput ().upload_folder ) == 33
214
+ assert ClearableFileInput ().upload_folder .startswith (
215
+ 'custom/location/tmp/s3file/'
216
+ )
217
+ assert len (ClearableFileInput ().upload_folder ) == 49
0 commit comments