chore: remove deprecated DEFAULT_FILE_STORAGE and STATICFILES_STORAGE settings (#37002)

This commit is contained in:
Ram Chandra Bhavirisetty
2025-09-05 15:52:33 -06:00
committed by GitHub
parent 06b54e79f2
commit 42afa1bb62
20 changed files with 249 additions and 50 deletions

View File

@@ -100,7 +100,13 @@ class TestThemingViews(TestCase):
assert response.status_code == 302
assert response.url == "/static/images/logo.png"
@override_settings(STATICFILES_STORAGE="openedx.core.storage.DevelopmentStorage")
@override_settings(
STORAGES={
'staticfiles': {
'BACKEND': 'openedx.core.storage.DevelopmentStorage'
}
}
)
def test_asset_with_theme(self):
"""
Fetch theme asset when a theme is set.

View File

@@ -1231,7 +1231,6 @@ class TestAccountsAPI(FilteredQueryCountMixin, CacheIsolationTestCase, UserAPITe
)
def test_profile_backend_with_default_hardcoded_backend(self):
""" In case of empty storages scenario uses the hardcoded backend."""
del settings.DEFAULT_FILE_STORAGE
del settings.STORAGES
storage = get_profile_image_storage()
self.assertIsInstance(storage, FileSystemStorage)

View File

@@ -54,7 +54,7 @@ class ProductionMixin(
We use this version on production.
"""
def __init__(self, *args, **kwargs):
kwargs.update(settings.STATICFILES_STORAGE_KWARGS.get(settings.STATICFILES_STORAGE, {}))
kwargs.update(settings.STATICFILES_STORAGE_KWARGS.get(settings.STORAGES['staticfiles']['BACKEND'], {}))
super().__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
@@ -112,5 +112,5 @@ def get_storage(storage_class=None, **kwargs):
the storage implementation makes http requests when instantiated, for
example.
"""
storage_cls = import_string(storage_class or settings.DEFAULT_FILE_STORAGE)
storage_cls = import_string(storage_class or settings.STORAGES["default"]["BACKEND"])
return storage_cls(**kwargs)

View File

@@ -0,0 +1,54 @@
"""
Tests for the get_storage utility function.
"""
from django.test import TestCase, override_settings
from django.core.files.storage import FileSystemStorage
from openedx.core.storage import get_storage
class TestGetStorage(TestCase):
"""
Tests of the get_storage function
"""
def setUp(self):
super().setUp()
get_storage.cache_clear()
def tearDown(self):
get_storage.cache_clear()
@override_settings(
STORAGES={
'default': {
'BACKEND': 'django.core.files.storage.FileSystemStorage'
}
}
)
def test_get_storage_returns_default_storage_when_no_class_specified(self):
"""Test that get_storage returns the default storage when no storage_class is provided."""
storage = get_storage()
self.assertIsInstance(storage, FileSystemStorage)
def test_get_storage_returns_custom_storage_when_class_specified(self):
"""Test that get_storage returns the specified storage class."""
storage_class = 'django.core.files.storage.FileSystemStorage'
storage = get_storage(storage_class=storage_class)
self.assertIsInstance(storage, FileSystemStorage)
def test_get_storage_caching_behavior(self):
"""Test that get_storage caches instances with identical arguments."""
storage_class = 'django.core.files.storage.FileSystemStorage'
kwargs = {'location': '/test/path'}
# First Call
storage1 = get_storage(storage_class=storage_class, **kwargs)
# Second Call
storage2 = get_storage(storage_class=storage_class, **kwargs)
self.assertIs(storage1, storage2)
def test_get_storage_handles_invalid_storage_class(self):
"""Test that get_storage raises appropriate error for invalid storage class."""
with self.assertRaises(ImportError):
get_storage(storage_class='nonexistent.storage.InvalidStorage')