summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2009-03-30 22:56:05 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2009-03-30 22:56:05 +0000
commit22ac97b17cbc3491629f98b15cc9a699b14ebd73 (patch)
tree1845663d43a471d3080068d034b1a78b52a1c5b0 /tests
parent86842e21f41602f4f6fbf0e61bf25bc4bc8e9256 (diff)
[1.0.X] Fixed #10149. FileFields? in a form now validate max_length. Based on a patch by Massimo Scamarcia. Backport of r10227 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10232 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/model_forms/models.py7
-rw-r--r--tests/regressiontests/forms/fields.py15
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index a202185ec6..1e72a553b1 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -93,7 +93,7 @@ class PhoneNumber(models.Model):
class TextFile(models.Model):
description = models.CharField(max_length=20)
- file = models.FileField(storage=temp_storage, upload_to='tests')
+ file = models.FileField(storage=temp_storage, upload_to='tests', max_length=15)
def __unicode__(self):
return self.description
@@ -974,6 +974,11 @@ True
>>> instance.file
<FieldFile: tests/test1.txt>
+# Check if the max_length attribute has been inherited from the model.
+>>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': SimpleUploadedFile('test-maxlength.txt', 'hello world')})
+>>> f.is_valid()
+False
+
# Edit an instance that already has the file defined in the model. This will not
# save the file again, but leave it exactly as it is.
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index fa5a62ac51..0dc49f2ca7 100644
--- a/tests/regressiontests/forms/fields.py
+++ b/tests/regressiontests/forms/fields.py
@@ -845,6 +845,21 @@ ValidationError: [u'The submitted file is empty.']
>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf'))
<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
+>>> f = FileField(max_length = 5)
+>>> f.clean(SimpleUploadedFile('test_maxlength.txt', 'hello world'))
+Traceback (most recent call last):
+...
+ValidationError: [u'Ensure this filename has at most 5 characters (it has 18).']
+
+>>> f.clean('', 'files/test1.pdf')
+'files/test1.pdf'
+
+>>> f.clean(None, 'files/test2.pdf')
+'files/test2.pdf'
+
+>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content')))
+<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
+
# URLField ##################################################################
>>> f = URLField()