From c458700382724e85d8572fc80cd829f54d57d43d Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 30 Dec 2011 14:51:05 +0000 Subject: [PATCH] Fixed #16590 -- Accepted a 'name' argument in the constructor of ContentFile, for consistency with File. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17298 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/files/base.py | 4 ++-- tests/regressiontests/file_storage/tests.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/django/core/files/base.py b/django/core/files/base.py index 6204d71040..48d0be43f0 100644 --- a/django/core/files/base.py +++ b/django/core/files/base.py @@ -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): diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index d4530bb0b1..d1ecbe60af 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -542,3 +542,14 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase): 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)