Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropbox: Add support to timeout #420

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -32,6 +32,7 @@ By order of apparition, thanks:
* Stanislav Kaledin (Bug fixes in SFTPStorage)
* Filip Vavera (Google Cloud MIME types support)
* Max Malysh (Dropbox large file support)
* Lucas Rangel Cezimbra (patches)

Extra thanks to Marty for adding this in Django,
you can buy his very interesting book (Pro Django).
9 changes: 8 additions & 1 deletion docs/backends/dropbox.rst
Expand Up @@ -20,8 +20,15 @@ To use DropBoxStorage set::
``DROPBOX_OAUTH2_TOKEN``
Your DropBox token, if you haven't follow this `guide step`_.

``DROPBOX_ROOT_PATH``
``DROPBOX_ROOT_PATH`` (optional)
Allow to jail your storage to a defined directory.

Default: ``/``

``DROPBOX_TIMEOUT`` (optional)
Timeout in seconds. After timeout the connection will be closed. If ``None``, client will wait forever.

Dropbox default: ``30`` seconds

.. _`guide step`: https://www.dropbox.com/developers/documentation/python#tutorial
.. _`Dropbox SDK for Python`: https://www.dropbox.com/developers/documentation/python#tutorial
8 changes: 6 additions & 2 deletions storages/backends/dropbox.py
Expand Up @@ -53,13 +53,17 @@ class DropBoxStorage(Storage):

CHUNK_SIZE = 4 * 1024 * 1024

def __init__(self, oauth2_access_token=None, root_path=None):
def __init__(self, oauth2_access_token=None, root_path=None, timeout=None):
oauth2_access_token = oauth2_access_token or setting('DROPBOX_OAUTH2_TOKEN')
self.root_path = root_path or setting('DROPBOX_ROOT_PATH', '/')
timeout = timeout or setting('DROPBOX_TIMEOUT')
if oauth2_access_token is None:
raise ImproperlyConfigured("You must configure a token auth at"
"'settings.DROPBOX_OAUTH2_TOKEN'.")
self.client = Dropbox(oauth2_access_token)
if timeout:
self.client = Dropbox(oauth2_access_token, timeout)
else:
self.client = Dropbox(oauth2_access_token)

def _full_path(self, name):
if name == '/':
Expand Down
17 changes: 17 additions & 0 deletions tests/test_dropbox.py
Expand Up @@ -150,6 +150,23 @@ def test_formats(self, *args):
self.assertEqual(files, self.storage._full_path('..'))
self.assertEqual(files, self.storage._full_path('../..'))

@mock.patch('storages.backends.dropbox.Dropbox')
def test_timeout_config(self, Dropbox):
token = 'abc'
timeout = 60

with self.settings(DROPBOX_OAUTH2_TOKEN=token, DROPBOX_TIMEOUT=timeout):
dropbox.DropBoxStorage()
Dropbox.assert_called_with(token, timeout)

with self.settings(DROPBOX_OAUTH2_TOKEN=token):
dropbox.DropBoxStorage(timeout=timeout)
Dropbox.assert_called_with(token, timeout)

with self.settings(DROPBOX_OAUTH2_TOKEN=token):
dropbox.DropBoxStorage()
Dropbox.assert_called_with(token)


class DropBoxFileTest(TestCase):
def setUp(self, *args):
Expand Down