diff --git a/django/core/files/base.py b/django/core/files/base.py index 8e974fee57..11049a45de 100644 --- a/django/core/files/base.py +++ b/django/core/files/base.py @@ -18,10 +18,6 @@ class File(FileProxyMixin): self.file = file if name is None: name = getattr(file, 'name', None) - # Use only the basename from a file's name if it's an absolute path, - # e.g. from NamedTemporaryFile. - if isinstance(name, six.string_types) and os.path.isabs(name): - name = os.path.basename(name) self.name = name if hasattr(file, 'mode'): self.mode = file.mode diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 24481730ea..44da2a547f 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -10,7 +10,6 @@ import threading import time import unittest from datetime import datetime, timedelta -from tempfile import NamedTemporaryFile from django.core.cache import cache from django.core.exceptions import SuspiciousFileOperation, SuspiciousOperation @@ -860,13 +859,6 @@ class FileFieldStorageTests(TestCase): with temp_storage.open('tests/stringio') as f: self.assertEqual(f.read(), b'content') - def test_save_temporary_file(self): - storage = Storage() - with NamedTemporaryFile() as f: - f.write(b'content') - storage.normal = File(f) - storage.save() # no crash - # Tests for a race condition on file saving (#4948). # This is written in such a way that it'll always pass on platforms diff --git a/tests/files/tests.py b/tests/files/tests.py index d20c2d47bc..4ff3b1f49c 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -26,12 +26,6 @@ else: class FileTests(unittest.TestCase): - - def test_file_truncates_namedtemporaryfile_name(self): - named_file = NamedTemporaryFile() - f = File(named_file) - self.assertEqual(f.name, os.path.basename(named_file.name)) - def test_unicode_uploadedfile_name(self): uf = UploadedFile(name='¿Cómo?', content_type='text') self.assertIs(type(repr(uf)), str)