Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed unnecessary bytes prefix for ContentFile

  • Loading branch information...
commit b5240d25c1bf724f0008478e7f6cccd0a6d6bd1e 1 parent 361d673
Claude Paroz authored August 29, 2012
12  tests/modeltests/files/tests.py
@@ -20,7 +20,7 @@ def tearDown(self):
20 20
         shutil.rmtree(temp_storage_location)
21 21
 
22 22
     def test_files(self):
23  
-        temp_storage.save('tests/default.txt', ContentFile(b'default content'))
  23
+        temp_storage.save('tests/default.txt', ContentFile('default content'))
24 24
         # Attempting to access a FileField from the class raises a descriptive
25 25
         # error
26 26
         self.assertRaises(AttributeError, lambda: Storage.normal)
@@ -31,7 +31,7 @@ def test_files(self):
31 31
         self.assertRaises(ValueError, lambda: obj1.normal.size)
32 32
 
33 33
         # Saving a file enables full functionality.
34  
-        obj1.normal.save("django_test.txt", ContentFile(b"content"))
  34
+        obj1.normal.save("django_test.txt", ContentFile("content"))
35 35
         self.assertEqual(obj1.normal.name, "tests/django_test.txt")
36 36
         self.assertEqual(obj1.normal.size, 7)
37 37
         self.assertEqual(obj1.normal.read(), b"content")
@@ -59,7 +59,7 @@ def test_files(self):
59 59
 
60 60
         # Save another file with the same name.
61 61
         obj2 = Storage()
62  
-        obj2.normal.save("django_test.txt", ContentFile(b"more content"))
  62
+        obj2.normal.save("django_test.txt", ContentFile("more content"))
63 63
         self.assertEqual(obj2.normal.name, "tests/django_test_1.txt")
64 64
         self.assertEqual(obj2.normal.size, 12)
65 65
 
@@ -70,13 +70,13 @@ def test_files(self):
70 70
 
71 71
         # Deleting an object does not delete the file it uses.
72 72
         obj2.delete()
73  
-        obj2.normal.save("django_test.txt", ContentFile(b"more content"))
  73
+        obj2.normal.save("django_test.txt", ContentFile("more content"))
74 74
         self.assertEqual(obj2.normal.name, "tests/django_test_2.txt")
75 75
 
76 76
         # Multiple files with the same name get _N appended to them.
77 77
         objs = [Storage() for i in range(3)]
78 78
         for o in objs:
79  
-            o.normal.save("multiple_files.txt", ContentFile(b"Same Content"))
  79
+            o.normal.save("multiple_files.txt", ContentFile("Same Content"))
80 80
         self.assertEqual(
81 81
             [o.normal.name for o in objs],
82 82
             ["tests/multiple_files.txt", "tests/multiple_files_1.txt", "tests/multiple_files_2.txt"]
@@ -100,7 +100,7 @@ def test_files(self):
100 100
         # Verify the fix for #5655, making sure the directory is only
101 101
         # determined once.
102 102
         obj4 = Storage()
103  
-        obj4.random.save("random_file", ContentFile(b"random content"))
  103
+        obj4.random.save("random_file", ContentFile("random content"))
104 104
         self.assertTrue(obj4.random.name.endswith("/random_file"))
105 105
 
106 106
     def test_max_length(self):
42  tests/regressiontests/file_storage/tests.py
@@ -128,7 +128,7 @@ def test_file_accessed_time(self):
128 128
         """
129 129
         self.assertFalse(self.storage.exists('test.file'))
130 130
 
131  
-        f = ContentFile(b'custom contents')
  131
+        f = ContentFile('custom contents')
132 132
         f_name = self.storage.save('test.file', f)
133 133
         atime = self.storage.accessed_time(f_name)
134 134
 
@@ -144,7 +144,7 @@ def test_file_created_time(self):
144 144
         """
145 145
         self.assertFalse(self.storage.exists('test.file'))
146 146
 
147  
-        f = ContentFile(b'custom contents')
  147
+        f = ContentFile('custom contents')
148 148
         f_name = self.storage.save('test.file', f)
149 149
         ctime = self.storage.created_time(f_name)
150 150
 
@@ -161,7 +161,7 @@ def test_file_modified_time(self):
161 161
         """
162 162
         self.assertFalse(self.storage.exists('test.file'))
163 163
 
164  
-        f = ContentFile(b'custom contents')
  164
+        f = ContentFile('custom contents')
165 165
         f_name = self.storage.save('test.file', f)
166 166
         mtime = self.storage.modified_time(f_name)
167 167
 
@@ -178,7 +178,7 @@ def test_file_save_without_name(self):
178 178
         """
179 179
         self.assertFalse(self.storage.exists('test.file'))
180 180
 
181  
-        f = ContentFile(b'custom contents')
  181
+        f = ContentFile('custom contents')
182 182
         f.name = 'test.file'
183 183
 
184 184
         storage_f_name = self.storage.save(None, f)
@@ -195,7 +195,7 @@ def test_file_save_with_path(self):
195 195
         """
196 196
         self.assertFalse(self.storage.exists('path/to'))
197 197
         self.storage.save('path/to/test.file',
198  
-            ContentFile(b'file saved with path'))
  198
+            ContentFile('file saved with path'))
199 199
 
200 200
         self.assertTrue(self.storage.exists('path/to'))
201 201
         with self.storage.open('path/to/test.file') as f:
@@ -212,7 +212,7 @@ def test_file_path(self):
212 212
         """
213 213
         self.assertFalse(self.storage.exists('test.file'))
214 214
 
215  
-        f = ContentFile(b'custom contents')
  215
+        f = ContentFile('custom contents')
216 216
         f_name = self.storage.save('test.file', f)
217 217
 
218 218
         self.assertEqual(self.storage.path(f_name),
@@ -247,8 +247,8 @@ def test_listdir(self):
247 247
         self.assertFalse(self.storage.exists('storage_test_2'))
248 248
         self.assertFalse(self.storage.exists('storage_dir_1'))
249 249
 
250  
-        f = self.storage.save('storage_test_1', ContentFile(b'custom content'))
251  
-        f = self.storage.save('storage_test_2', ContentFile(b'custom content'))
  250
+        f = self.storage.save('storage_test_1', ContentFile('custom content'))
  251
+        f = self.storage.save('storage_test_2', ContentFile('custom content'))
252 252
         os.mkdir(os.path.join(self.temp_dir, 'storage_dir_1'))
253 253
 
254 254
         dirs, files = self.storage.listdir('')
@@ -305,18 +305,18 @@ def fake_makedirs(path):
305 305
             os.makedirs = fake_makedirs
306 306
 
307 307
             self.storage.save('normal/test.file',
308  
-                ContentFile(b'saved normally'))
  308
+                ContentFile('saved normally'))
309 309
             with self.storage.open('normal/test.file') as f:
310 310
                 self.assertEqual(f.read(), b'saved normally')
311 311
 
312 312
             self.storage.save('raced/test.file',
313  
-                ContentFile(b'saved with race'))
  313
+                ContentFile('saved with race'))
314 314
             with self.storage.open('raced/test.file') as f:
315 315
                 self.assertEqual(f.read(), b'saved with race')
316 316
 
317 317
             # Check that OSErrors aside from EEXIST are still raised.
318 318
             self.assertRaises(OSError,
319  
-                self.storage.save, 'error/test.file', ContentFile(b'not saved'))
  319
+                self.storage.save, 'error/test.file', ContentFile('not saved'))
320 320
         finally:
321 321
             os.makedirs = real_makedirs
322 322
 
@@ -342,16 +342,16 @@ def fake_remove(path):
342 342
         try:
343 343
             os.remove = fake_remove
344 344
 
345  
-            self.storage.save('normal.file', ContentFile(b'delete normally'))
  345
+            self.storage.save('normal.file', ContentFile('delete normally'))
346 346
             self.storage.delete('normal.file')
347 347
             self.assertFalse(self.storage.exists('normal.file'))
348 348
 
349  
-            self.storage.save('raced.file', ContentFile(b'delete with race'))
  349
+            self.storage.save('raced.file', ContentFile('delete with race'))
350 350
             self.storage.delete('raced.file')
351 351
             self.assertFalse(self.storage.exists('normal.file'))
352 352
 
353 353
             # Check that OSErrors aside from ENOENT are still raised.
354  
-            self.storage.save('error.file', ContentFile(b'delete with error'))
  354
+            self.storage.save('error.file', ContentFile('delete with error'))
355 355
             self.assertRaises(OSError, self.storage.delete, 'error.file')
356 356
         finally:
357 357
             os.remove = real_remove
@@ -375,9 +375,9 @@ class CustomStorageTests(FileStorageTests):
375 375
     storage_class = CustomStorage
376 376
 
377 377
     def test_custom_get_available_name(self):
378  
-        first = self.storage.save('custom_storage', ContentFile(b'custom contents'))
  378
+        first = self.storage.save('custom_storage', ContentFile('custom contents'))
379 379
         self.assertEqual(first, 'custom_storage')
380  
-        second = self.storage.save('custom_storage', ContentFile(b'more contents'))
  380
+        second = self.storage.save('custom_storage', ContentFile('more contents'))
381 381
         self.assertEqual(second, 'custom_storage.2')
382 382
         self.storage.delete(first)
383 383
         self.storage.delete(second)
@@ -434,7 +434,7 @@ def tearDown(self):
434 434
         shutil.rmtree(self.storage_dir)
435 435
 
436 436
     def test_file_upload_permissions(self):
437  
-        name = self.storage.save("the_file", ContentFile(b"data"))
  437
+        name = self.storage.save("the_file", ContentFile("data"))
438 438
         actual_mode = os.stat(self.storage.path(name))[0] & 0o777
439 439
         self.assertEqual(actual_mode, 0o666)
440 440
 
@@ -454,8 +454,8 @@ def test_directory_with_dot(self):
454 454
         sure we still mangle the file name instead of the directory name.
455 455
         """
456 456
 
457  
-        self.storage.save('dotted.path/test', ContentFile(b"1"))
458  
-        self.storage.save('dotted.path/test', ContentFile(b"2"))
  457
+        self.storage.save('dotted.path/test', ContentFile("1"))
  458
+        self.storage.save('dotted.path/test', ContentFile("2"))
459 459
 
460 460
         self.assertFalse(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path')))
461 461
         self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test')))
@@ -466,8 +466,8 @@ def test_first_character_dot(self):
466 466
         File names with a dot as their first character don't have an extension,
467 467
         and the underscore should get added to the end.
468 468
         """
469  
-        self.storage.save('dotted.path/.test', ContentFile(b"1"))
470  
-        self.storage.save('dotted.path/.test', ContentFile(b"2"))
  469
+        self.storage.save('dotted.path/.test', ContentFile("1"))
  470
+        self.storage.save('dotted.path/.test', ContentFile("2"))
471 471
 
472 472
         self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test')))
473 473
         self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test_1')))

0 notes on commit b5240d2

Please sign in to comment.
Something went wrong with that request. Please try again.