diff options
| author | tom christie tom@tomchristie.com | 2011-04-02 16:32:37 +0100 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-04-02 16:32:37 +0100 |
| commit | 4687db680cda52e9836743940e4cf7279b307294 (patch) | |
| tree | 23b9b22eee3c08f6de09295b3c6630f5fb0730fa /djangorestframework/tests/files.py | |
| parent | 8845b281fe9aafbc9f9b2a283fafbde9787f4734 (diff) | |
| download | django-rest-framework-4687db680cda52e9836743940e4cf7279b307294.tar.bz2 | |
Refactor to use self.CONTENT to access request body. Get file upload working
Diffstat (limited to 'djangorestframework/tests/files.py')
| -rw-r--r-- | djangorestframework/tests/files.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/djangorestframework/tests/files.py b/djangorestframework/tests/files.py new file mode 100644 index 00000000..e155f181 --- /dev/null +++ b/djangorestframework/tests/files.py @@ -0,0 +1,37 @@ +from django.test import TestCase +from django import forms +from djangorestframework.compat import RequestFactory +from djangorestframework.resource import Resource +import StringIO + +class UploadFilesTests(TestCase): + """Check uploading of files""" + def setUp(self): + self.factory = RequestFactory() + + def test_upload_file(self): + + + class FileForm(forms.Form): + file = forms.FileField + + class MockResource(Resource): + allowed_methods = anon_allowed_methods = ('POST',) + form = FileForm + + def post(self, request, auth, content, *args, **kwargs): + #self.uploaded = content.file + return {'FILE_NAME': content['file'].name, + 'FILE_CONTENT': content['file'].read()} + + file = StringIO.StringIO('stuff') + file.name = 'stuff.txt' + request = self.factory.post('/', {'file': file}) + view = MockResource.as_view() + response = view(request) + self.assertEquals(response.content, '{"FILE_CONTENT": "stuff", "FILE_NAME": "stuff.txt"}') + + + + + |
