From 215e0818b48aee36cf43f2831bab4956e19c74c9 Mon Sep 17 00:00:00 2001 From: Lucas Rangel Cezimbra Date: Thu, 2 Nov 2017 20:07:00 -0200 Subject: [PATCH 1/3] Dropbox: Add support to timeout config --- storages/backends/dropbox.py | 8 ++++++-- tests/test_dropbox.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index bae6deadb..aa911d5e4 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -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 == '/': diff --git a/tests/test_dropbox.py b/tests/test_dropbox.py index 58d503628..650528017 100644 --- a/tests/test_dropbox.py +++ b/tests/test_dropbox.py @@ -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): From ebc379e86c0acd6404ce7b7ed5dd37d5121fc465 Mon Sep 17 00:00:00 2001 From: Lucas Rangel Cezimbra Date: Thu, 2 Nov 2017 20:36:00 -0200 Subject: [PATCH 2/3] Dropbox: update documentation --- docs/backends/dropbox.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/backends/dropbox.rst b/docs/backends/dropbox.rst index 6b7aa1fbc..8e01a5d5b 100644 --- a/docs/backends/dropbox.rst +++ b/docs/backends/dropbox.rst @@ -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 From 3533ca5f27b6d327642cd5a04e688398122b7d7b Mon Sep 17 00:00:00 2001 From: Lucas Rangel Cezimbra Date: Thu, 2 Nov 2017 20:36:45 -0200 Subject: [PATCH 3/3] Update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 25db7d015..6ac9535e3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -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).