1
- import os
2
-
3
- from mock import mock
4
-
5
- import cloudinary
6
1
from django .core .files .uploadedfile import SimpleUploadedFile
7
2
from django .test import TestCase
3
+ from mock import mock
8
4
9
- from cloudinary import api , CloudinaryResource
5
+ import cloudinary
6
+ from cloudinary import CloudinaryResource
10
7
from cloudinary .forms import CloudinaryFileField
8
+ from django_tests .forms import CloudinaryJsTestFileForm
11
9
from django_tests .helper_test import SUFFIX , TEST_IMAGE , TEST_IMAGE_W , TEST_IMAGE_H
12
10
13
11
API_TEST_ID = "dj_test_{}" .format (SUFFIX )
@@ -17,13 +15,14 @@ class TestCloudinaryFileField(TestCase):
17
15
def setUp (self ):
18
16
self .test_file = SimpleUploadedFile (TEST_IMAGE , b'content' )
19
17
20
- def test_to_python (self ):
18
+ def test_file_field (self ):
21
19
cff_no_auto_save = CloudinaryFileField (autosave = False )
22
20
res = cff_no_auto_save .to_python (None )
23
21
self .assertIsNone (res )
24
22
# without auto_save File is untouched
25
23
res = cff_no_auto_save .to_python (self .test_file )
26
24
self .assertIsInstance (res , SimpleUploadedFile )
25
+
27
26
# when auto_save is used, resource is uploaded to Cloudinary and CloudinaryResource is returned
28
27
cff_auto_save = CloudinaryFileField (autosave = True , options = {"public_id" : API_TEST_ID })
29
28
mocked_resource = cloudinary .CloudinaryResource (metadata = {"width" : TEST_IMAGE_W , "height" : TEST_IMAGE_H },
@@ -36,5 +35,15 @@ def test_to_python(self):
36
35
self .assertIsInstance (res , CloudinaryResource )
37
36
self .assertEqual (API_TEST_ID , res .public_id )
38
37
38
+ def test_js_file_field (self ):
39
+ js_file_form = CloudinaryJsTestFileForm ()
40
+
41
+ rendered_form = js_file_form .as_p ()
42
+
43
+ self .assertIn ("margin-top: 30px" , rendered_form )
44
+ self .assertIn ("directly_uploaded" , rendered_form )
45
+ self .assertIn ("c_fill,h_100,w_150" , rendered_form )
46
+ self .assertIn ("c_limit,h_1000,w_1000" , rendered_form )
47
+
39
48
def tearDown (self ):
40
49
pass
0 commit comments