mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
Merge pull request #545 from yprez/filefield-no-files_issue542
FileField validation with files=None
This commit is contained in:
commit
ed9f20823b
|
@ -21,6 +21,7 @@ Major version numbers (x.0.0) are reserved for project milestones. No major poi
|
|||
* Added `PATCH` support.
|
||||
* Added `RetrieveUpdateAPIView`.
|
||||
* Relation changes are now persisted in `save` instead of in `.restore_object`.
|
||||
* Bugfix: Fix issue with FileField validation with files=None.
|
||||
|
||||
### 2.1.14
|
||||
|
||||
|
|
|
@ -181,6 +181,7 @@ class WritableField(Field):
|
|||
|
||||
try:
|
||||
if self._use_files:
|
||||
files = files or {}
|
||||
native = files[field_name]
|
||||
else:
|
||||
native = data[field_name]
|
||||
|
|
|
@ -25,7 +25,6 @@ class UploadedFileSerializer(serializers.Serializer):
|
|||
|
||||
|
||||
class FileSerializerTests(TestCase):
|
||||
|
||||
def test_create(self):
|
||||
now = datetime.datetime.now()
|
||||
file = StringIO.StringIO('stuff')
|
||||
|
@ -37,3 +36,16 @@ class FileSerializerTests(TestCase):
|
|||
self.assertEquals(serializer.object.created, uploaded_file.created)
|
||||
self.assertEquals(serializer.object.file, uploaded_file.file)
|
||||
self.assertFalse(serializer.object is uploaded_file)
|
||||
|
||||
def test_creation_failure(self):
|
||||
"""
|
||||
Passing files=None should result in an ValidationError
|
||||
|
||||
Regression test for:
|
||||
https://github.com/tomchristie/django-rest-framework/issues/542
|
||||
"""
|
||||
now = datetime.datetime.now()
|
||||
|
||||
serializer = UploadedFileSerializer(data={'created': now})
|
||||
self.assertFalse(serializer.is_valid())
|
||||
self.assertIn('file', serializer.errors)
|
||||
|
|
Loading…
Reference in New Issue
Block a user