Add validation error test when passing non-file to FileField

This commit is contained in:
Tom Christie 2013-08-23 12:03:54 +01:00
parent 47d17b088a
commit 95b2bf50fb

View File

@ -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]})