mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Add validation error test when passing non-file to FileField
This commit is contained in:
parent
47d17b088a
commit
95b2bf50fb
|
@ -69,3 +69,14 @@ class FileSerializerTests(TestCase):
|
|||
self.assertTrue(serializer.is_valid())
|
||||
self.assertEqual(serializer.object.created, uploaded_file.created)
|
||||
self.assertIsNone(serializer.object.file)
|
||||
|
||||
def test_validation_error_with_non_file(self):
|
||||
"""
|
||||
Passing non-files should raise a validation error.
|
||||
"""
|
||||
now = datetime.datetime.now()
|
||||
errmsg = 'No file was submitted. Check the encoding type on the form.'
|
||||
|
||||
serializer = UploadedFileSerializer(data={'created': now, 'file': 'abc'})
|
||||
self.assertFalse(serializer.is_valid())
|
||||
self.assertEqual(serializer.errors, {'file': [errmsg]})
|
||||
|
|
Loading…
Reference in New Issue
Block a user