Skip to content

Commit

Permalink
Fix .save method of the Dropbox backend (jschneier#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmalysh committed Aug 10, 2017
1 parent dc3902d commit fce162b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion storages/backends/dropbox.py
Expand Up @@ -108,5 +108,7 @@ def _open(self, name, mode='rb'):
return remote_file

def _save(self, name, content):
self.client.files_upload(content, self._full_path(name))
content.open()
self.client.files_upload(content.read(), self._full_path(name))
content.close()
return name
6 changes: 4 additions & 2 deletions tests/test_dropbox.py
Expand Up @@ -5,6 +5,7 @@
)
from django.core.files.base import ContentFile, File
from django.test import TestCase
from django.utils.six import BytesIO

from storages.backends import dropbox

Expand Down Expand Up @@ -118,8 +119,9 @@ def test_open(self, *args):

@mock.patch('dropbox.Dropbox.files_upload',
return_value='foo')
def test_save(self, *args):
self.storage._save('foo', b'bar')
def test_save(self, files_upload, *args):
self.storage._save('foo', File(BytesIO(b'bar'), 'foo'))
self.assertTrue(files_upload.called)

@mock.patch('dropbox.Dropbox.files_get_temporary_link',
return_value=FILE_MEDIA_FIXTURE)
Expand Down

0 comments on commit fce162b

Please sign in to comment.