Skip to content

Commit

Permalink
[dropbox] Fix setting oauth2 access token via env var (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschneier authored Sep 22, 2024
1 parent b85d021 commit 1725606
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion storages/backends/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class DropboxStorage(BaseStorage):
CHUNK_SIZE = 4 * 1024 * 1024

def __init__(self, oauth2_access_token=None, **settings):
super().__init__(oauth2_access_token=oauth2_access_token, **settings)
if oauth2_access_token is not None:
settings["oauth2_access_token"] = oauth2_access_token
super().__init__(**settings)

if self.oauth2_access_token is None and not all(
[self.app_key, self.app_secret, self.oauth2_refresh_token]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.core.exceptions import SuspiciousFileOperation
from django.core.files.base import File
from django.test import TestCase
from django.test import override_settings
from dropbox.files import FileMetadata
from dropbox.files import FolderMetadata
from dropbox.files import GetTemporaryLinkResult
Expand Down Expand Up @@ -54,6 +55,11 @@ def test_no_access_token(self, *args):
with self.assertRaises(ImproperlyConfigured):
dropbox.DropboxStorage(None)

def test_setting_access_token(self):
with override_settings(DROPBOX_OAUTH2_TOKEN="abc"):
storage = dropbox.DropboxStorage()
self.assertEqual(storage.oauth2_access_token, "abc")

def test_refresh_token_app_key_no_app_secret(self, *args):
inputs = {
"oauth2_refresh_token": "foo",
Expand Down

0 comments on commit 1725606

Please sign in to comment.