From 1725606693005cab72475989abc759187c612b6e Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sat, 21 Sep 2024 20:17:20 -0400 Subject: [PATCH] [dropbox] Fix setting oauth2 access token via env var (#1452) --- storages/backends/dropbox.py | 4 +++- tests/test_dropbox.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index 1d291cdd..d28757ae 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -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] diff --git a/tests/test_dropbox.py b/tests/test_dropbox.py index c56de10e..6dd386b1 100644 --- a/tests/test_dropbox.py +++ b/tests/test_dropbox.py @@ -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 @@ -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",