Ticket #16590: 16590.patch

File 16590.patch, 1.4 KB (added by Aymeric Augustin, 13 years ago)
  • tests/regressiontests/file_storage/tests.py

     
    542542        size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image)
    543543        self.assertEqual(image_pil.size, size_1)
    544544        self.assertEqual(size_1, size_2)
     545
     546class ContentFileTestCase(unittest.TestCase):
     547    """
     548    Test that the constructor of ContentFile accepts 'name' (#16590).
     549    """
     550    def test_content_file_default_name(self):
     551        self.assertEqual(ContentFile("content").name, None)
     552
     553    def test_content_file_custome_name(self):
     554        name = "I can have a name too!"
     555        self.assertEqual(ContentFile("content", name=name).name, name)
  • django/core/files/base.py

     
    122122    """
    123123    A File-like object that takes just raw content, rather than an actual file.
    124124    """
    125     def __init__(self, content):
     125    def __init__(self, content, name=None):
    126126        content = content or ''
    127         super(ContentFile, self).__init__(StringIO(content))
     127        super(ContentFile, self).__init__(StringIO(content), name=name)
    128128        self.size = len(content)
    129129
    130130    def __str__(self):
Back to Top