Code

Ticket #11739: 11739_with_test.diff

File 11739_with_test.diff, 1.3 KB (added by cody@…, 3 years ago)

Same as last patch but with a test

Line 
1diff --git a/django/core/files/base.py b/django/core/files/base.py
2index 6204d71..6a82f80 100644
3--- a/django/core/files/base.py
4+++ b/django/core/files/base.py
5@@ -1,8 +1,5 @@
6 import os
7-try:
8-    from cStringIO import StringIO
9-except ImportError:
10-    from StringIO import StringIO
11+from StringIO import StringIO
12 
13 from django.utils.encoding import smart_str, smart_unicode
14 from django.core.files.utils import FileProxyMixin
15diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
16index d4530bb..5864732 100644
17--- a/tests/regressiontests/file_storage/tests.py
18+++ b/tests/regressiontests/file_storage/tests.py
19@@ -542,3 +542,15 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
20         size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image)
21         self.assertEqual(image_pil.size, size_1)
22         self.assertEqual(size_1, size_2)
23+
24+class UnicodeContentFileBug(unittest.TestCase):
25+    """
26+    Tests that ContentFile instances can contain unicode (#11739)
27+    """
28+    def test_unicode(self):
29+        """
30+        ContentFile instances should be able to handle unicode.
31+        """
32+        snowman = u'☃'
33+        file = ContentFile(snowman)
34+        self.assertEqual(file.read(), snowman)