From ebc5a9974d6cffb6df89f326e8d4466b5faaeeba Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sun, 12 Jun 2011 20:23:40 +0100 Subject: [PATCH] Fix file uploads --- djangorestframework/resources.py | 2 +- djangorestframework/tests/files.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/djangorestframework/resources.py b/djangorestframework/resources.py index cc4b64712..07c97d439 100644 --- a/djangorestframework/resources.py +++ b/djangorestframework/resources.py @@ -314,7 +314,7 @@ class FormResource(Resource): if not form: return None - if data is not None: + if data is not None or files is not None: return form(data, files) return form() diff --git a/djangorestframework/tests/files.py b/djangorestframework/tests/files.py index 25aad9b49..992d3cbab 100644 --- a/djangorestframework/tests/files.py +++ b/djangorestframework/tests/files.py @@ -12,20 +12,16 @@ class UploadFilesTests(TestCase): def test_upload_file(self): - class FileForm(forms.Form): - file = forms.FileField - - class MockResource(FormResource): - form = FileForm + file = forms.FileField() class MockView(View): permissions = () - resource = MockResource + form = FileForm def post(self, request, *args, **kwargs): - return {'FILE_NAME': self.CONTENT['file'][0].name, - 'FILE_CONTENT': self.CONTENT['file'][0].read()} + return {'FILE_NAME': self.CONTENT['file'].name, + 'FILE_CONTENT': self.CONTENT['file'].read()} file = StringIO.StringIO('stuff') file.name = 'stuff.txt'