diff options
| author | Henry Dang <henrydangprg@gmail.com> | 2016-11-26 13:23:03 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-11-29 16:12:24 -0500 |
| commit | 7cddd8a02e60332c0d02f565c450b0eea0d88438 (patch) | |
| tree | 26c56407b91b81d8a61027ff381f024324af4931 /tests/invalid_models_tests/test_ordinary_fields.py | |
| parent | b8a815e9dfea89034ede7ff786551f89af84a31b (diff) | |
Fixed #27358 -- Added a system check to prevent FileField's upload_to from starting with a slash.
Thanks Frank Bijlsma for the initial patch.
Diffstat (limited to 'tests/invalid_models_tests/test_ordinary_fields.py')
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index aff6a74659..c005fe9331 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -455,6 +455,31 @@ class FileFieldTests(SimpleTestCase): ] self.assertEqual(errors, expected) + def test_upload_to_starts_with_slash(self): + class Model(models.Model): + field = models.FileField(upload_to='/somewhere') + + field = Model._meta.get_field('field') + self.assertEqual(field.check(), [ + Error( + "FileField's 'upload_to' argument must be a relative path, not " + "an absolute path.", + obj=field, + id='fields.E202', + hint='Remove the leading slash.', + ) + ]) + + def test_upload_to_callable_not_checked(self): + def callable(instance, filename): + return '/' + filename + + class Model(models.Model): + field = models.FileField(upload_to=callable) + + field = Model._meta.get_field('field') + self.assertEqual(field.check(), []) + @isolate_apps('invalid_models_tests') class FilePathFieldTests(SimpleTestCase): |
