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] Fix setting oauth2 access token via env var #1452

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading