Removed unnecessary bytes prefix for ContentFile
This commit is contained in:
parent
361d6738f8
commit
b5240d25c1
|
@ -20,7 +20,7 @@ class FileStorageTests(TestCase):
|
|||
shutil.rmtree(temp_storage_location)
|
||||
|
||||
def test_files(self):
|
||||
temp_storage.save('tests/default.txt', ContentFile(b'default content'))
|
||||
temp_storage.save('tests/default.txt', ContentFile('default content'))
|
||||
# Attempting to access a FileField from the class raises a descriptive
|
||||
# error
|
||||
self.assertRaises(AttributeError, lambda: Storage.normal)
|
||||
|
@ -31,7 +31,7 @@ class FileStorageTests(TestCase):
|
|||
self.assertRaises(ValueError, lambda: obj1.normal.size)
|
||||
|
||||
# Saving a file enables full functionality.
|
||||
obj1.normal.save("django_test.txt", ContentFile(b"content"))
|
||||
obj1.normal.save("django_test.txt", ContentFile("content"))
|
||||
self.assertEqual(obj1.normal.name, "tests/django_test.txt")
|
||||
self.assertEqual(obj1.normal.size, 7)
|
||||
self.assertEqual(obj1.normal.read(), b"content")
|
||||
|
@ -59,7 +59,7 @@ class FileStorageTests(TestCase):
|
|||
|
||||
# Save another file with the same name.
|
||||
obj2 = Storage()
|
||||
obj2.normal.save("django_test.txt", ContentFile(b"more content"))
|
||||
obj2.normal.save("django_test.txt", ContentFile("more content"))
|
||||
self.assertEqual(obj2.normal.name, "tests/django_test_1.txt")
|
||||
self.assertEqual(obj2.normal.size, 12)
|
||||
|
||||
|
@ -70,13 +70,13 @@ class FileStorageTests(TestCase):
|
|||
|
||||
# Deleting an object does not delete the file it uses.
|
||||
obj2.delete()
|
||||
obj2.normal.save("django_test.txt", ContentFile(b"more content"))
|
||||
obj2.normal.save("django_test.txt", ContentFile("more content"))
|
||||
self.assertEqual(obj2.normal.name, "tests/django_test_2.txt")
|
||||
|
||||
# Multiple files with the same name get _N appended to them.
|
||||
objs = [Storage() for i in range(3)]
|
||||
for o in objs:
|
||||
o.normal.save("multiple_files.txt", ContentFile(b"Same Content"))
|
||||
o.normal.save("multiple_files.txt", ContentFile("Same Content"))
|
||||
self.assertEqual(
|
||||
[o.normal.name for o in objs],
|
||||
["tests/multiple_files.txt", "tests/multiple_files_1.txt", "tests/multiple_files_2.txt"]
|
||||
|
@ -100,7 +100,7 @@ class FileStorageTests(TestCase):
|
|||
# Verify the fix for #5655, making sure the directory is only
|
||||
# determined once.
|
||||
obj4 = Storage()
|
||||
obj4.random.save("random_file", ContentFile(b"random content"))
|
||||
obj4.random.save("random_file", ContentFile("random content"))
|
||||
self.assertTrue(obj4.random.name.endswith("/random_file"))
|
||||
|
||||
def test_max_length(self):
|
||||
|
|
|
@ -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…
Reference in New Issue