23
23
from django.core.files.storage import FileSystemStorage, get_storage_class
24
24
from django.core.files.uploadedfile import UploadedFile
25
25
from django.test import SimpleTestCase
26
-
from django.utils import unittest
26
+
from django.utils import six, unittest
27
27
28
28
# Try to import PIL in either of the two ways it can end up installed.
29
29
# Checking for the existence of Image is enough for CPython, but
37
37
Image = None
38
38
39
39
40
+
FILE_SUFFIX_REGEX = '[A-Za-z0-9]{7}'
41
+
42
+
40
43
class GetStorageClassTests(SimpleTestCase):
41
44
42
45
def test_get_filesystem_storage(self):
@@ -417,10 +420,9 @@ def test_race_condition(self):
417
420
self.thread.start()
418
421
name = self.save_file('conflict')
419
422
self.thread.join()
420
-
self.assertTrue(self.storage.exists('conflict'))
421
-
self.assertTrue(self.storage.exists('conflict_1'))
422
-
self.storage.delete('conflict')
423
-
self.storage.delete('conflict_1')
423
+
files = sorted(os.listdir(self.storage_dir))
424
+
self.assertEqual(files[0], 'conflict')
425
+
six.assertRegex(self, files[1], 'conflict_%s' % FILE_SUFFIX_REGEX)
424
426
425
427
class FileStoragePermissions(unittest.TestCase):
426
428
def setUp(self):
@@ -457,9 +459,10 @@ def test_directory_with_dot(self):
457
459
self.storage.save('dotted.path/test', ContentFile("1"))
458
460
self.storage.save('dotted.path/test', ContentFile("2"))
459
461
462
+
files = sorted(os.listdir(os.path.join(self.storage_dir, 'dotted.path')))
460
463
self.assertFalse(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path')))
461
-
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test')))
462
-
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test_1')))
464
+
self.assertEqual(files[0], 'test')
465
+
six.assertRegex(self, files[1], 'test_%s' % FILE_SUFFIX_REGEX)
463
466
464
467
def test_first_character_dot(self):
465
468
"""
@@ -472,10 +475,12 @@ def test_first_character_dot(self):
472
475
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test')))
473
476
# Before 2.6, a leading dot was treated as an extension, and so
474
477
# underscore gets added to beginning instead of end.
478
+
files = sorted(os.listdir(os.path.join(self.storage_dir, 'dotted.path')))
479
+
self.assertEqual(files[0], '.test')
475
480
if sys.version_info < (2, 6):
476
-
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/_1.test')))
481
+
six.assertRegex(self, files[1], '_%s.test' % FILE_SUFFIX_REGEX)
477
482
else:
478
-
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test_1')))
483
+
six.assertRegex(self, files[1], '.test_%s' % FILE_SUFFIX_REGEX)
479
484
480
485
class DimensionClosingBug(unittest.TestCase):
481
486
"""
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4