From fea6c73538148a7362a9cdd85bbc4732ddb4204d Mon Sep 17 00:00:00 2001 From: Joseph Kocherhans Date: Mon, 30 Mar 2009 22:52:16 +0000 Subject: Fixed #10149. FileFields in a form now validate max_length. Based on a patch by Massimo Scamarcia. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10227 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/fields.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/regressiontests/forms') 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')) +>>> 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'))) + + # URLField ################################################################## >>> f = URLField() -- cgit v1.3