Skip to content

Commit

Permalink
Add validation error test when passing non-file to FileField
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Aug 23, 2013
1 parent 47d17b0 commit 95b2bf5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rest_framework/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ def test_remove_with_empty_string(self):
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]})

0 comments on commit 95b2bf5

Please sign in to comment.