summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-05-17 16:02:05 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-05-17 16:02:05 +0200
commitdcd4383107d96c18bcb53312ca4de070374b334c (patch)
tree674b9d393cc35a63fff255b5b58a8e359f3566d3 /tests
parent82a76ef67d944b1a4507cac81476bebba0c90e4a (diff)
Fixed #9893 -- Validated the length of file names
after the full file name is generated by the storage class. Thanks Refefer for the report, carsongee for the patch, and everyone else involved in the discussion.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/model_fields/tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index ea1e1c7d99..4b48616e99 100644
--- a/tests/regressiontests/model_fields/tests.py
+++ b/tests/regressiontests/model_fields/tests.py
@@ -365,3 +365,15 @@ class FileFieldTests(unittest.TestCase):
field = d._meta.get_field('myfile')
field.save_form_data(d, 'else.txt')
self.assertEqual(d.myfile, 'else.txt')
+
+ 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 'unused/xxxxx'.
+ # max_length = 100, so names longer than 93 characters are rejected.
+ Document(myfile=93 * 'x').full_clean()
+ with self.assertRaises(ValidationError):
+ Document(myfile=94 * 'x').full_clean()