7
7
from selenium .webdriver .support .expected_conditions import staleness_of
8
8
from selenium .webdriver .support .wait import WebDriverWait
9
9
10
- from s3file .forms import S3FileInput
10
+ from s3file .forms import S3FileInputMixin
11
11
from tests .testapp .forms import UploadForm
12
12
13
13
try :
@@ -33,13 +33,15 @@ def url(self):
33
33
34
34
@pytest .fixture (autouse = True )
35
35
def patch (self ):
36
- ClearableFileInput .__new__ = \
37
- lambda cls , * args , ** kwargs : object .__new__ (S3FileInput )
36
+ if S3FileInputMixin not in ClearableFileInput .__bases__ :
37
+ ClearableFileInput .__bases__ = \
38
+ (S3FileInputMixin ,) + ClearableFileInput .__bases__
39
+ pass
38
40
39
41
@pytest .fixture
40
42
def freeze (self , monkeypatch ):
41
43
"""Freeze datetime and UUID."""
42
- monkeypatch .setattr ('s3file.forms.S3FileInput .upload_folder' , 'tmp' )
44
+ monkeypatch .setattr ('s3file.forms.S3FileInputMixin .upload_folder' , 'tmp' )
43
45
44
46
def test_value_from_datadict (self , client , upload_file ):
45
47
with open (upload_file ) as f :
@@ -78,7 +80,7 @@ def test_clear(self, filemodel):
78
80
assert not form .cleaned_data ['file' ]
79
81
80
82
def test_build_attr (self ):
81
- assert set (S3FileInput ().build_attrs ({}).keys ()) == {
83
+ assert set (ClearableFileInput ().build_attrs ({}).keys ()) == {
82
84
'class' ,
83
85
'data-url' ,
84
86
'data-fields-x-amz-algorithm' ,
@@ -88,11 +90,12 @@ def test_build_attr(self):
88
90
'data-fields-policy' ,
89
91
'data-fields-key' ,
90
92
}
91
- assert S3FileInput ().build_attrs ({})['class' ] == 's3file'
92
- assert S3FileInput ().build_attrs ({'class' : 'my-class' })['class' ] == 'my-class s3file'
93
+ assert ClearableFileInput ().build_attrs ({})['class' ] == 's3file'
94
+ assert ClearableFileInput ().build_attrs (
95
+ {'class' : 'my-class' })['class' ] == 'my-class s3file'
93
96
94
97
def test_get_conditions (self , freeze ):
95
- conditions = S3FileInput ().get_conditions (None )
98
+ conditions = ClearableFileInput ().get_conditions (None )
96
99
assert all (condition in conditions for condition in [
97
100
{"bucket" : 'test-bucket' },
98
101
{"success_action_status" : "201" },
@@ -101,15 +104,15 @@ def test_get_conditions(self, freeze):
101
104
]), conditions
102
105
103
106
def test_accept (self ):
104
- widget = S3FileInput ()
107
+ widget = ClearableFileInput ()
105
108
assert 'accept' not in widget .render (name = 'file' , value = 'test.jpg' )
106
109
assert ["starts-with" , "$Content-Type" , "" ] in widget .get_conditions (None )
107
110
108
- widget = S3FileInput (attrs = {'accept' : 'image/*' })
111
+ widget = ClearableFileInput (attrs = {'accept' : 'image/*' })
109
112
assert 'accept="image/*"' in widget .render (name = 'file' , value = 'test.jpg' )
110
113
assert ["starts-with" , "$Content-Type" , "image/" ] in widget .get_conditions ('image/*' )
111
114
112
- widget = S3FileInput (attrs = {'accept' : 'image/jpeg' })
115
+ widget = ClearableFileInput (attrs = {'accept' : 'image/jpeg' })
113
116
assert 'accept="image/jpeg"' in widget .render (name = 'file' , value = 'test.jpg' )
114
117
assert {"Content-Type" : 'image/jpeg' } in widget .get_conditions ('image/jpeg' )
115
118
0 commit comments