|
21 | 21 | from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
22 | 22 | from xmodule.modulestore.xml_importer import import_course_from_xml
|
23 | 23 |
|
| 24 | +from common.djangoapps.util.storage import resolve_storage_backend |
| 25 | +from storages.backends.s3boto3 import S3Boto3Storage |
| 26 | + |
24 | 27 | TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
|
25 | 28 | TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex
|
26 | 29 |
|
@@ -275,3 +278,81 @@ def test_video_components_present_while_import(self):
|
275 | 278 |
|
276 | 279 | video = module_store.get_item(vertical.children[1])
|
277 | 280 | self.assertEqual(video.display_name, 'default')
|
| 281 | + |
| 282 | + @override_settings( |
| 283 | + COURSE_IMPORT_EXPORT_STORAGE="cms.djangoapps.contentstore.storage.ImportExportS3Storage", |
| 284 | + DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage" |
| 285 | + ) |
| 286 | + def test_resolve_default_storage(self): |
| 287 | + """ Ensure the default storage is invoked, even if course export storage is configured """ |
| 288 | + storage = resolve_storage_backend( |
| 289 | + storage_key="default", |
| 290 | + legacy_setting_key="DEFAULT_FILE_STORAGE" |
| 291 | + ) |
| 292 | + self.assertEqual(storage.__class__.__name__, "FileSystemStorage") |
| 293 | + |
| 294 | + @override_settings( |
| 295 | + COURSE_IMPORT_EXPORT_STORAGE="cms.djangoapps.contentstore.storage.ImportExportS3Storage", |
| 296 | + DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage", |
| 297 | + COURSE_IMPORT_EXPORT_BUCKET="bucket_name_test" |
| 298 | + ) |
| 299 | + def test_resolve_happy_path_storage(self): |
| 300 | + """ Make sure that the correct course export storage is being used """ |
| 301 | + storage = resolve_storage_backend( |
| 302 | + storage_key="course_import_export", |
| 303 | + legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE" |
| 304 | + ) |
| 305 | + self.assertEqual(storage.__class__.__name__, "ImportExportS3Storage") |
| 306 | + self.assertEqual(storage.bucket_name, "bucket_name_test") |
| 307 | + |
| 308 | + @override_settings() |
| 309 | + def test_resolve_storage_with_no_config(self): |
| 310 | + """ If no storage setup is defined, we get FileSystemStorage by default """ |
| 311 | + del settings.DEFAULT_FILE_STORAGE |
| 312 | + del settings.COURSE_IMPORT_EXPORT_STORAGE |
| 313 | + del settings.COURSE_IMPORT_EXPORT_BUCKET |
| 314 | + storage = resolve_storage_backend( |
| 315 | + storage_key="course_import_export", |
| 316 | + legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE" |
| 317 | + ) |
| 318 | + self.assertEqual(storage.__class__.__name__, "FileSystemStorage") |
| 319 | + |
| 320 | + @override_settings( |
| 321 | + COURSE_IMPORT_EXPORT_STORAGE=None, |
| 322 | + COURSE_IMPORT_EXPORT_BUCKET="bucket_name_test", |
| 323 | + STORAGES={ |
| 324 | + 'COURSE_IMPORT_EXPORT_STORAGE': { |
| 325 | + 'BACKEND': 'cms.djangoapps.contentstore.storage.ImportExportS3Storage', |
| 326 | + 'OPTIONS': {} |
| 327 | + } |
| 328 | + } |
| 329 | + ) |
| 330 | + def test_resolve_storage_using_django5_settings(self): |
| 331 | + """ Simulating a Django 4 environment using Django 5 Storages configuration """ |
| 332 | + storage = resolve_storage_backend( |
| 333 | + storage_key="course_import_export", |
| 334 | + legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE" |
| 335 | + ) |
| 336 | + self.assertEqual(storage.__class__.__name__, "ImportExportS3Storage") |
| 337 | + self.assertEqual(storage.bucket_name, "bucket_name_test") |
| 338 | + |
| 339 | + @override_settings( |
| 340 | + STORAGES={ |
| 341 | + 'course_import_export': { |
| 342 | + 'BACKEND': 'storages.backends.s3boto3.S3Boto3Storage', |
| 343 | + 'OPTIONS': { |
| 344 | + 'bucket_name': 'bucket_name_test' |
| 345 | + } |
| 346 | + } |
| 347 | + } |
| 348 | + ) |
| 349 | + def test_resolve_storage_using_django5_settings_with_options(self): |
| 350 | + """ Ensure we call the storage class with the correct parameters and Django 5 setup """ |
| 351 | + del settings.COURSE_IMPORT_EXPORT_STORAGE |
| 352 | + del settings.COURSE_IMPORT_EXPORT_BUCKET |
| 353 | + storage = resolve_storage_backend( |
| 354 | + storage_key="course_import_export", |
| 355 | + legacy_setting_key="COURSE_IMPORT_EXPORT_STORAGE" |
| 356 | + ) |
| 357 | + self.assertEqual(storage.__class__.__name__, S3Boto3Storage.__name__) |
| 358 | + self.assertEqual(storage.bucket_name, "bucket_name_test") |
0 commit comments