77from selenium .webdriver .support .expected_conditions import staleness_of
88from selenium .webdriver .support .wait import WebDriverWait
99
10- from s3file .forms import S3FileInput
10+ from s3file .forms import S3FileInputMixin
1111from tests .testapp .forms import UploadForm
1212
1313try :
@@ -33,13 +33,15 @@ def url(self):
3333
3434 @pytest .fixture (autouse = True )
3535 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
3840
3941 @pytest .fixture
4042 def freeze (self , monkeypatch ):
4143 """Freeze datetime and UUID."""
42- monkeypatch .setattr ('s3file.forms.S3FileInput .upload_folder' , 'tmp' )
44+ monkeypatch .setattr ('s3file.forms.S3FileInputMixin .upload_folder' , 'tmp' )
4345
4446 def test_value_from_datadict (self , client , upload_file ):
4547 with open (upload_file ) as f :
@@ -78,7 +80,7 @@ def test_clear(self, filemodel):
7880 assert not form .cleaned_data ['file' ]
7981
8082 def test_build_attr (self ):
81- assert set (S3FileInput ().build_attrs ({}).keys ()) == {
83+ assert set (ClearableFileInput ().build_attrs ({}).keys ()) == {
8284 'class' ,
8385 'data-url' ,
8486 'data-fields-x-amz-algorithm' ,
@@ -88,11 +90,12 @@ def test_build_attr(self):
8890 'data-fields-policy' ,
8991 'data-fields-key' ,
9092 }
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'
9396
9497 def test_get_conditions (self , freeze ):
95- conditions = S3FileInput ().get_conditions (None )
98+ conditions = ClearableFileInput ().get_conditions (None )
9699 assert all (condition in conditions for condition in [
97100 {"bucket" : 'test-bucket' },
98101 {"success_action_status" : "201" },
@@ -101,15 +104,15 @@ def test_get_conditions(self, freeze):
101104 ]), conditions
102105
103106 def test_accept (self ):
104- widget = S3FileInput ()
107+ widget = ClearableFileInput ()
105108 assert 'accept' not in widget .render (name = 'file' , value = 'test.jpg' )
106109 assert ["starts-with" , "$Content-Type" , "" ] in widget .get_conditions (None )
107110
108- widget = S3FileInput (attrs = {'accept' : 'image/*' })
111+ widget = ClearableFileInput (attrs = {'accept' : 'image/*' })
109112 assert 'accept="image/*"' in widget .render (name = 'file' , value = 'test.jpg' )
110113 assert ["starts-with" , "$Content-Type" , "image/" ] in widget .get_conditions ('image/*' )
111114
112- widget = S3FileInput (attrs = {'accept' : 'image/jpeg' })
115+ widget = ClearableFileInput (attrs = {'accept' : 'image/jpeg' })
113116 assert 'accept="image/jpeg"' in widget .render (name = 'file' , value = 'test.jpg' )
114117 assert {"Content-Type" : 'image/jpeg' } in widget .get_conditions ('image/jpeg' )
115118
0 commit comments