mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Removed unnecessary bytes prefix for ContentFile
This commit is contained in:
parent
361d6738f8
commit
b5240d25c1
2 changed files with 27 additions and 27 deletions
|
@ -128,7 +128,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('test.file'))
|
||||
|
||||
f = ContentFile(b'custom contents')
|
||||
f = ContentFile('custom contents')
|
||||
f_name = self.storage.save('test.file', f)
|
||||
atime = self.storage.accessed_time(f_name)
|
||||
|
||||
|
@ -144,7 +144,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('test.file'))
|
||||
|
||||
f = ContentFile(b'custom contents')
|
||||
f = ContentFile('custom contents')
|
||||
f_name = self.storage.save('test.file', f)
|
||||
ctime = self.storage.created_time(f_name)
|
||||
|
||||
|
@ -161,7 +161,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('test.file'))
|
||||
|
||||
f = ContentFile(b'custom contents')
|
||||
f = ContentFile('custom contents')
|
||||
f_name = self.storage.save('test.file', f)
|
||||
mtime = self.storage.modified_time(f_name)
|
||||
|
||||
|
@ -178,7 +178,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('test.file'))
|
||||
|
||||
f = ContentFile(b'custom contents')
|
||||
f = ContentFile('custom contents')
|
||||
f.name = 'test.file'
|
||||
|
||||
storage_f_name = self.storage.save(None, f)
|
||||
|
@ -195,7 +195,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('path/to'))
|
||||
self.storage.save('path/to/test.file',
|
||||
ContentFile(b'file saved with path'))
|
||||
ContentFile('file saved with path'))
|
||||
|
||||
self.assertTrue(self.storage.exists('path/to'))
|
||||
with self.storage.open('path/to/test.file') as f:
|
||||
|
@ -212,7 +212,7 @@ class FileStorageTests(unittest.TestCase):
|
|||
"""
|
||||
self.assertFalse(self.storage.exists('test.file'))
|
||||
|
||||
f = ContentFile(b'custom contents')
|
||||
f = ContentFile('custom contents')
|
||||
f_name = self.storage.save('test.file', f)
|
||||
|
||||
self.assertEqual(self.storage.path(f_name),
|
||||
|
@ -247,8 +247,8 @@ class FileStorageTests(unittest.TestCase):
|
|||
self.assertFalse(self.storage.exists('storage_test_2'))
|
||||
self.assertFalse(self.storage.exists('storage_dir_1'))
|
||||
|
||||
f = self.storage.save('storage_test_1', ContentFile(b'custom content'))
|
||||
f = self.storage.save('storage_test_2', ContentFile(b'custom content'))
|
||||
f = self.storage.save('storage_test_1', ContentFile('custom content'))
|
||||
f = self.storage.save('storage_test_2', ContentFile('custom content'))
|
||||
os.mkdir(os.path.join(self.temp_dir, 'storage_dir_1'))
|
||||
|
||||
dirs, files = self.storage.listdir('')
|
||||
|
@ -305,18 +305,18 @@ class FileStorageTests(unittest.TestCase):
|
|||
os.makedirs = fake_makedirs
|
||||
|
||||
self.storage.save('normal/test.file',
|
||||
ContentFile(b'saved normally'))
|
||||
ContentFile('saved normally'))
|
||||
with self.storage.open('normal/test.file') as f:
|
||||
self.assertEqual(f.read(), b'saved normally')
|
||||
|
||||
self.storage.save('raced/test.file',
|
||||
ContentFile(b'saved with race'))
|
||||
ContentFile('saved with race'))
|
||||
with self.storage.open('raced/test.file') as f:
|
||||
self.assertEqual(f.read(), b'saved with race')
|
||||
|
||||
# Check that OSErrors aside from EEXIST are still raised.
|
||||
self.assertRaises(OSError,
|
||||
self.storage.save, 'error/test.file', ContentFile(b'not saved'))
|
||||
self.storage.save, 'error/test.file', ContentFile('not saved'))
|
||||
finally:
|
||||
os.makedirs = real_makedirs
|
||||
|
||||
|
@ -342,16 +342,16 @@ class FileStorageTests(unittest.TestCase):
|
|||
try:
|
||||
os.remove = fake_remove
|
||||
|
||||
self.storage.save('normal.file', ContentFile(b'delete normally'))
|
||||
self.storage.save('normal.file', ContentFile('delete normally'))
|
||||
self.storage.delete('normal.file')
|
||||
self.assertFalse(self.storage.exists('normal.file'))
|
||||
|
||||
self.storage.save('raced.file', ContentFile(b'delete with race'))
|
||||
self.storage.save('raced.file', ContentFile('delete with race'))
|
||||
self.storage.delete('raced.file')
|
||||
self.assertFalse(self.storage.exists('normal.file'))
|
||||
|
||||
# Check that OSErrors aside from ENOENT are still raised.
|
||||
self.storage.save('error.file', ContentFile(b'delete with error'))
|
||||
self.storage.save('error.file', ContentFile('delete with error'))
|
||||
self.assertRaises(OSError, self.storage.delete, 'error.file')
|
||||
finally:
|
||||
os.remove = real_remove
|
||||
|
@ -375,9 +375,9 @@ class CustomStorageTests(FileStorageTests):
|
|||
storage_class = CustomStorage
|
||||
|
||||
def test_custom_get_available_name(self):
|
||||
first = self.storage.save('custom_storage', ContentFile(b'custom contents'))
|
||||
first = self.storage.save('custom_storage', ContentFile('custom contents'))
|
||||
self.assertEqual(first, 'custom_storage')
|
||||
second = self.storage.save('custom_storage', ContentFile(b'more contents'))
|
||||
second = self.storage.save('custom_storage', ContentFile('more contents'))
|
||||
self.assertEqual(second, 'custom_storage.2')
|
||||
self.storage.delete(first)
|
||||
self.storage.delete(second)
|
||||
|
@ -434,7 +434,7 @@ class FileStoragePermissions(unittest.TestCase):
|
|||
shutil.rmtree(self.storage_dir)
|
||||
|
||||
def test_file_upload_permissions(self):
|
||||
name = self.storage.save("the_file", ContentFile(b"data"))
|
||||
name = self.storage.save("the_file", ContentFile("data"))
|
||||
actual_mode = os.stat(self.storage.path(name))[0] & 0o777
|
||||
self.assertEqual(actual_mode, 0o666)
|
||||
|
||||
|
@ -454,8 +454,8 @@ class FileStoragePathParsing(unittest.TestCase):
|
|||
sure we still mangle the file name instead of the directory name.
|
||||
"""
|
||||
|
||||
self.storage.save('dotted.path/test', ContentFile(b"1"))
|
||||
self.storage.save('dotted.path/test', ContentFile(b"2"))
|
||||
self.storage.save('dotted.path/test', ContentFile("1"))
|
||||
self.storage.save('dotted.path/test', ContentFile("2"))
|
||||
|
||||
self.assertFalse(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path')))
|
||||
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test')))
|
||||
|
@ -466,8 +466,8 @@ class FileStoragePathParsing(unittest.TestCase):
|
|||
File names with a dot as their first character don't have an extension,
|
||||
and the underscore should get added to the end.
|
||||
"""
|
||||
self.storage.save('dotted.path/.test', ContentFile(b"1"))
|
||||
self.storage.save('dotted.path/.test', ContentFile(b"2"))
|
||||
self.storage.save('dotted.path/.test', ContentFile("1"))
|
||||
self.storage.save('dotted.path/.test', ContentFile("2"))
|
||||
|
||||
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test')))
|
||||
self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test_1')))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue