4040 Image = None
4141
4242
43+ FILE_SUFFIX_REGEX = '[A-Za-z0-9]{7}'
44+
45+
4346class GetStorageClassTests (SimpleTestCase ):
4447
4548 def test_get_filesystem_storage (self ):
@@ -431,10 +434,9 @@ def test_race_condition(self):
431434 self .thread .start ()
432435 name = self .save_file ('conflict' )
433436 self .thread .join ()
434- self .assertTrue (self .storage .exists ('conflict' ))
435- self .assertTrue (self .storage .exists ('conflict_1' ))
436- self .storage .delete ('conflict' )
437- self .storage .delete ('conflict_1' )
437+ files = sorted (os .listdir (self .storage_dir ))
438+ self .assertEqual (files [0 ], 'conflict' )
439+ six .assertRegex (self , files [1 ], 'conflict_%s' % FILE_SUFFIX_REGEX )
438440
439441@unittest .skipIf (sys .platform .startswith ('win' ), "Windows only partially supports umasks and chmod." )
440442class FileStoragePermissions (unittest .TestCase ):
@@ -478,9 +480,10 @@ def test_directory_with_dot(self):
478480 self .storage .save ('dotted.path/test' , ContentFile ("1" ))
479481 self .storage .save ('dotted.path/test' , ContentFile ("2" ))
480482
483+ files = sorted (os .listdir (os .path .join (self .storage_dir , 'dotted.path' )))
481484 self .assertFalse (os .path .exists (os .path .join (self .storage_dir , 'dotted_.path' )))
482- self .assertTrue ( os . path . exists ( os . path . join ( self . storage_dir , 'dotted.path/ test' )) )
483- self . assertTrue ( os . path . exists ( os . path . join ( self . storage_dir , 'dotted.path/test_1' )) )
485+ self .assertEqual ( files [ 0 ] , 'test' )
486+ six . assertRegex ( self , files [ 1 ], 'test_%s' % FILE_SUFFIX_REGEX )
484487
485488 def test_first_character_dot (self ):
486489 """
@@ -490,8 +493,10 @@ def test_first_character_dot(self):
490493 self .storage .save ('dotted.path/.test' , ContentFile ("1" ))
491494 self .storage .save ('dotted.path/.test' , ContentFile ("2" ))
492495
493- self .assertTrue (os .path .exists (os .path .join (self .storage_dir , 'dotted.path/.test' )))
494- self .assertTrue (os .path .exists (os .path .join (self .storage_dir , 'dotted.path/.test_1' )))
496+ files = sorted (os .listdir (os .path .join (self .storage_dir , 'dotted.path' )))
497+ self .assertFalse (os .path .exists (os .path .join (self .storage_dir , 'dotted_.path' )))
498+ self .assertEqual (files [0 ], '.test' )
499+ six .assertRegex (self , files [1 ], '.test_%s' % FILE_SUFFIX_REGEX )
495500
496501class DimensionClosingBug (unittest .TestCase ):
497502 """
0 commit comments