1- import os
2-
3- from mock import mock
4-
5- import cloudinary
61from django .core .files .uploadedfile import SimpleUploadedFile
72from django .test import TestCase
3+ from mock import mock
84
9- from cloudinary import api , CloudinaryResource
5+ import cloudinary
6+ from cloudinary import CloudinaryResource
107from cloudinary .forms import CloudinaryFileField
8+ from django_tests .forms import CloudinaryJsTestFileForm
119from django_tests .helper_test import SUFFIX , TEST_IMAGE , TEST_IMAGE_W , TEST_IMAGE_H
1210
1311API_TEST_ID = "dj_test_{}" .format (SUFFIX )
@@ -17,13 +15,14 @@ class TestCloudinaryFileField(TestCase):
1715 def setUp (self ):
1816 self .test_file = SimpleUploadedFile (TEST_IMAGE , b'content' )
1917
20- def test_to_python (self ):
18+ def test_file_field (self ):
2119 cff_no_auto_save = CloudinaryFileField (autosave = False )
2220 res = cff_no_auto_save .to_python (None )
2321 self .assertIsNone (res )
2422 # without auto_save File is untouched
2523 res = cff_no_auto_save .to_python (self .test_file )
2624 self .assertIsInstance (res , SimpleUploadedFile )
25+
2726 # when auto_save is used, resource is uploaded to Cloudinary and CloudinaryResource is returned
2827 cff_auto_save = CloudinaryFileField (autosave = True , options = {"public_id" : API_TEST_ID })
2928 mocked_resource = cloudinary .CloudinaryResource (metadata = {"width" : TEST_IMAGE_W , "height" : TEST_IMAGE_H },
@@ -36,5 +35,15 @@ def test_to_python(self):
3635 self .assertIsInstance (res , CloudinaryResource )
3736 self .assertEqual (API_TEST_ID , res .public_id )
3837
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+
3948 def tearDown (self ):
4049 pass
0 commit comments