Skip to content

Commit

Permalink
Fixed #16590 -- Accepted a 'name' argument in the constructor of Cont…
Browse files Browse the repository at this point in the history
…entFile, for consistency with File.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17298 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
aaugustin committed Dec 30, 2011
1 parent a99157d commit bd9494e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django/core/files/base.py
Expand Up @@ -122,9 +122,9 @@ class ContentFile(File):
"""
A File-like object that takes just raw content, rather than an actual file.
"""
def __init__(self, content):
def __init__(self, content, name=None):
content = content or ''
super(ContentFile, self).__init__(StringIO(content))
super(ContentFile, self).__init__(StringIO(content), name=name)
self.size = len(content)

def __str__(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/file_storage/tests.py
Expand Up @@ -542,3 +542,14 @@ def test_multiple_calls(self):
size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image)
self.assertEqual(image_pil.size, size_1)
self.assertEqual(size_1, size_2)

class ContentFileTestCase(unittest.TestCase):
"""
Test that the constructor of ContentFile accepts 'name' (#16590).
"""
def test_content_file_default_name(self):
self.assertEqual(ContentFile("content").name, None)

def test_content_file_custome_name(self):
name = "I can have a name too!"
self.assertEqual(ContentFile("content", name=name).name, name)

0 comments on commit bd9494e

Please sign in to comment.