Skip to content

feat: removing get_storage_class from COURSE_IMPORT_STORAGE #36849

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

Merged
merged 1 commit into from
Jun 20, 2025
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
7 changes: 5 additions & 2 deletions cms/djangoapps/contentstore/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from django.conf import settings
from django.core.files.storage import get_storage_class
from common.djangoapps.util.storage import resolve_storage_backend
from storages.backends.s3boto3 import S3Boto3Storage
from storages.utils import setting

Expand All @@ -19,4 +19,7 @@ def __init__(self):
super().__init__(bucket_name=bucket, custom_domain=None, querystring_auth=True)

# pylint: disable=invalid-name
course_import_export_storage = get_storage_class(settings.COURSE_IMPORT_EXPORT_STORAGE)()
course_import_export_storage = resolve_storage_backend(
storage_key="course_import_export",
legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE"
)
81 changes: 81 additions & 0 deletions cms/djangoapps/contentstore/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.xml_importer import import_course_from_xml

from common.djangoapps.util.storage import resolve_storage_backend
from storages.backends.s3boto3 import S3Boto3Storage

TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex

Expand Down Expand Up @@ -275,3 +278,81 @@ def test_video_components_present_while_import(self):

video = module_store.get_item(vertical.children[1])
self.assertEqual(video.display_name, 'default')

@override_settings(
COURSE_IMPORT_EXPORT_STORAGE="cms.djangoapps.contentstore.storage.ImportExportS3Storage",
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage"
)
def test_resolve_default_storage(self):
""" Ensure the default storage is invoked, even if course export storage is configured """
storage = resolve_storage_backend(
storage_key="default",
legacy_setting_key="DEFAULT_FILE_STORAGE"
)
self.assertEqual(storage.__class__.__name__, "FileSystemStorage")

@override_settings(
COURSE_IMPORT_EXPORT_STORAGE="cms.djangoapps.contentstore.storage.ImportExportS3Storage",
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage",
COURSE_IMPORT_EXPORT_BUCKET="bucket_name_test"
)
def test_resolve_happy_path_storage(self):
""" Make sure that the correct course export storage is being used """
storage = resolve_storage_backend(
storage_key="course_import_export",
legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE"
)
self.assertEqual(storage.__class__.__name__, "ImportExportS3Storage")
self.assertEqual(storage.bucket_name, "bucket_name_test")

@override_settings()
def test_resolve_storage_with_no_config(self):
""" If no storage setup is defined, we get FileSystemStorage by default """
del settings.DEFAULT_FILE_STORAGE
del settings.COURSE_IMPORT_EXPORT_STORAGE
del settings.COURSE_IMPORT_EXPORT_BUCKET
storage = resolve_storage_backend(
storage_key="course_import_export",
legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE"
)
self.assertEqual(storage.__class__.__name__, "FileSystemStorage")

@override_settings(
COURSE_IMPORT_EXPORT_STORAGE=None,
COURSE_IMPORT_EXPORT_BUCKET="bucket_name_test",
STORAGES={
'course_import_export': {
'BACKEND': 'cms.djangoapps.contentstore.storage.ImportExportS3Storage',
'OPTIONS': {}
}
}
)
def test_resolve_storage_using_django5_settings(self):
""" Simulating a Django 4 environment using Django 5 Storages configuration """
storage = resolve_storage_backend(
storage_key="course_import_export",
legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE"
)
self.assertEqual(storage.__class__.__name__, "ImportExportS3Storage")
self.assertEqual(storage.bucket_name, "bucket_name_test")

@override_settings(
STORAGES={
'course_import_export': {
'BACKEND': 'storages.backends.s3boto3.S3Boto3Storage',
'OPTIONS': {
'bucket_name': 'bucket_name_test'
}
}
}
)
def test_resolve_storage_using_django5_settings_with_options(self):
""" Ensure we call the storage class with the correct parameters and Django 5 setup """
del settings.COURSE_IMPORT_EXPORT_STORAGE
del settings.COURSE_IMPORT_EXPORT_BUCKET
storage = resolve_storage_backend(
storage_key="course_import_export",
legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE"
)
self.assertEqual(storage.__class__.__name__, S3Boto3Storage.__name__)
self.assertEqual(storage.bucket_name, "bucket_name_test")
Loading