mirror of https://github.com/django/django.git
Fixed #35658 -- Initialized InMemoryFileNode instances with a name.
This commit is contained in:
parent
69aa13ffb9
commit
f16a9a556f
|
@ -45,10 +45,9 @@ class InMemoryFileNode(ContentFile, TimingMixin):
|
|||
modification, and access times.
|
||||
"""
|
||||
|
||||
def __init__(self, content="", name=""):
|
||||
self.file = None
|
||||
def __init__(self, content="", name=None):
|
||||
super().__init__(content, name)
|
||||
self._content_type = type(content)
|
||||
self._initialize_stream()
|
||||
self._initialize_times()
|
||||
|
||||
def open(self, mode):
|
||||
|
@ -142,7 +141,11 @@ class InMemoryDirNode(TimingMixin):
|
|||
if create_if_missing:
|
||||
self._update_accessed_time()
|
||||
self._update_modified_time()
|
||||
return self._children.setdefault(path_segment, child_cls())
|
||||
if child_cls is InMemoryFileNode:
|
||||
child = child_cls(name=path_segment)
|
||||
else:
|
||||
child = child_cls()
|
||||
return self._children.setdefault(path_segment, child)
|
||||
return self._children.get(path_segment)
|
||||
|
||||
def listdir(self):
|
||||
|
|
|
@ -1024,6 +1024,23 @@ class FileFieldStorageTests(TestCase):
|
|||
with temp_storage.open("tests/stringio") as f:
|
||||
self.assertEqual(f.read(), b"content")
|
||||
|
||||
@override_settings(
|
||||
STORAGES={
|
||||
DEFAULT_STORAGE_ALIAS: {
|
||||
"BACKEND": "django.core.files.storage.InMemoryStorage"
|
||||
}
|
||||
}
|
||||
)
|
||||
def test_create_file_field_from_another_file_field_in_memory_storage(self):
|
||||
f = ContentFile("content", "file.txt")
|
||||
obj = Storage.objects.create(storage_callable_default=f)
|
||||
new_obj = Storage.objects.create(
|
||||
storage_callable_default=obj.storage_callable_default.file
|
||||
)
|
||||
storage = callable_default_storage()
|
||||
with storage.open(new_obj.storage_callable_default.name) as f:
|
||||
self.assertEqual(f.read(), b"content")
|
||||
|
||||
|
||||
class FieldCallableFileStorageTests(SimpleTestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue