@@ -47,7 +47,7 @@ def test_image_upload_success(self):
4747 self .assertEqual (response .status_code , 200 )
4848 self .assertEqual (response .json ()["code" ], 0 )
4949 self .assertEqual (response .json ()["msg" ], "Success!" )
50-
50+
5151 # Check that a URL was generated (exact filename will vary due to hash)
5252 response_data = response .json ()
5353 self .assertIn ("test_image.png" , response_data ["data" ]["succMap" ])
@@ -57,10 +57,11 @@ def test_image_upload_success(self):
5757
5858 # Verify that a file was created (filename will have hash prefix)
5959 import glob
60+
6061 file_pattern = os .path .join (settings .MEDIA_ROOT , "*_test_image.png" )
6162 matching_files = glob .glob (file_pattern )
6263 self .assertTrue (len (matching_files ) > 0 , "No uploaded file found" )
63-
64+
6465 # Verify file content
6566 if matching_files :
6667 with open (matching_files [0 ], "rb" ) as f :
@@ -94,8 +95,9 @@ class VditorWidgetTest(TestCase):
9495 def test_init (self ):
9596 # Clear cache to ensure we test actual configuration
9697 from django .core .cache import cache
98+
9799 cache .clear ()
98-
100+
99101 with override_settings (LANGUAGE_CODE = "en" ):
100102 widget = VditorWidget ()
101103 self .assertIsInstance (widget .config , dict )
@@ -192,10 +194,12 @@ def test_get_default_config(self):
192194 def test_vditor_config_init_default (self ):
193195 # Clear cache to ensure we test actual configuration
194196 from django .core .cache import cache
197+
195198 cache .clear ()
196-
199+
197200 # Reset language code to default
198201 from django .test import override_settings
202+
199203 with override_settings (LANGUAGE_CODE = "en" ):
200204 config = VditorConfig ()
201205 self .assertIsInstance (config , dict )
@@ -207,8 +211,9 @@ def test_vditor_config_init_default(self):
207211 def test_vditor_config_init_custom_language (self ):
208212 # Clear cache to ensure we test the actual language setting
209213 from django .core .cache import cache
214+
210215 cache .clear ()
211-
216+
212217 config = VditorConfig ()
213218 self .assertEqual (config ["lang" ], "fr_FR" )
214219
@@ -225,8 +230,9 @@ def test_vditor_config_init_custom_config(self):
225230 def test_vditor_config_improperly_configured_not_dict (self ):
226231 # Clear cache to ensure we test the actual configuration loading
227232 from django .core .cache import cache
233+
228234 cache .clear ()
229-
235+
230236 with self .assertRaisesMessage (
231237 ImproperlyConfigured , "VDITOR_CONFIGS setting must be a dictionary type."
232238 ):
@@ -236,11 +242,12 @@ def test_vditor_config_improperly_configured_not_dict(self):
236242 def test_vditor_config_improperly_configured_config_not_found (self ):
237243 # Clear cache to ensure we test the actual configuration loading
238244 from django .core .cache import cache
245+
239246 cache .clear ()
240-
247+
241248 with self .assertRaises (ImproperlyConfigured ) as cm :
242249 VditorConfig (config_name = "non_existent" )
243-
250+
244251 error_msg = str (cm .exception )
245252 self .assertIn ("No configuration named 'non_existent' found" , error_msg )
246253 self .assertIn ("Available configurations:" , error_msg )
@@ -267,60 +274,62 @@ def test_vditor_text_form_field_widget(self):
267274
268275class VditorSecurityTest (TestCase ):
269276 """Test security features."""
270-
277+
271278 def test_filename_validation (self ):
272279 from vditor .views import _validate_filename_security
273-
280+
274281 # Valid filename
275282 self .assertTrue (_validate_filename_security ("test.png" )[0 ])
276-
283+
277284 # Invalid filenames
278285 self .assertFalse (_validate_filename_security ("../test.png" )[0 ])
279286 self .assertFalse (_validate_filename_security ("test<>.png" )[0 ])
280287 self .assertFalse (_validate_filename_security ("CON.png" )[0 ])
281288 self .assertFalse (_validate_filename_security ("test~.png" )[0 ])
282-
289+
283290 def test_file_validation_size (self ):
284291 from django .core .files .uploadedfile import SimpleUploadedFile
285292 from vditor .views import _validate_uploaded_file
286-
293+
287294 # Too small file
288295 small_file = SimpleUploadedFile ("test.png" , b"x" , content_type = "image/png" )
289296 is_valid , error = _validate_uploaded_file (small_file )
290297 self .assertFalse (is_valid )
291298 self .assertIn ("too small" , error )
292-
299+
293300 # Valid file
294- valid_file = SimpleUploadedFile ("test.png" , b"x" * 100 , content_type = "image/png" )
301+ valid_file = SimpleUploadedFile (
302+ "test.png" , b"x" * 100 , content_type = "image/png"
303+ )
295304 is_valid , error = _validate_uploaded_file (valid_file )
296305 self .assertTrue (is_valid )
297306
298307
299308class VditorCacheTest (TestCase ):
300309 """Test caching functionality."""
301-
310+
302311 def test_config_caching (self ):
303312 from vditor .cache_utils import ConfigCache
304-
313+
305314 # Test setting and getting config
306315 test_config = {"test" : "value" }
307316 ConfigCache .set_config ("test_config" , test_config )
308-
317+
309318 retrieved_config = ConfigCache .get_config ("test_config" )
310319 self .assertEqual (retrieved_config , test_config )
311-
320+
312321 # Test invalidation
313322 ConfigCache .invalidate_config ("test_config" )
314323 self .assertIsNone (ConfigCache .get_config ("test_config" ))
315-
324+
316325 def test_media_cache (self ):
317326 from vditor .cache_utils import MediaCache
318-
327+
319328 # Test media hash generation
320329 hash1 = MediaCache .get_media_hash ()
321330 hash2 = MediaCache .get_media_hash ()
322331 self .assertEqual (hash1 , hash2 ) # Should be cached
323-
332+
324333 # Test invalidation
325334 MediaCache .invalidate_media ()
326335 hash3 = MediaCache .get_media_hash ()
0 commit comments