mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[1.5.x] Fixed #19525 -- Reverted dcd4383107 and 05d333ba3b.
Refs #9893, #18515.
Thanks Russell for the report.
Backport of db278c3 from master.
This commit is contained in:
@@ -26,5 +26,5 @@ class Storage(models.Model):
|
||||
|
||||
normal = models.FileField(storage=temp_storage, upload_to='tests')
|
||||
custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
|
||||
random = models.FileField(storage=temp_storage, upload_to=random_upload_to, max_length=16)
|
||||
random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
|
||||
default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
|
||||
|
||||
@@ -5,7 +5,6 @@ import shutil
|
||||
import tempfile
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files import File
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
@@ -103,24 +102,6 @@ class FileStorageTests(TestCase):
|
||||
obj4.random.save("random_file", ContentFile("random content"))
|
||||
self.assertTrue(obj4.random.name.endswith("/random_file"))
|
||||
|
||||
def test_max_length(self):
|
||||
"""
|
||||
Test that FileField validates the length of the generated file name
|
||||
that will be stored in the database. Regression for #9893.
|
||||
"""
|
||||
# upload_to = 'unused', so file names are saved as '456/xxxxx'.
|
||||
# max_length = 16, so names longer than 12 characters are rejected.
|
||||
s1 = Storage(random=SimpleUploadedFile(12 * 'x', b"content"))
|
||||
s1.full_clean()
|
||||
with self.assertRaises(ValidationError):
|
||||
Storage(random=SimpleUploadedFile(13 * 'x', b"content")).full_clean()
|
||||
|
||||
# Ticket #18515: validation for an already saved file should not check
|
||||
# against a regenerated file name (and potentially raise a ValidationError
|
||||
# if max_length is exceeded
|
||||
s1.save()
|
||||
s1.full_clean()
|
||||
|
||||
|
||||
class FileTests(unittest.TestCase):
|
||||
def test_context_manager(self):
|
||||
|
||||
Reference in New Issue
Block a user