|
| 1 | +import django |
| 2 | +from django.test import TestCase, override_settings |
| 3 | +from django.conf import settings |
| 4 | +from django.core.files.storage import FileSystemStorage |
| 5 | +import unittest |
| 6 | + |
| 7 | +from import_export_celery.fields import lazy_initialize_storage_class |
| 8 | + |
| 9 | + |
| 10 | +class FooTestingStorage(FileSystemStorage): |
| 11 | + pass |
| 12 | + |
| 13 | + |
| 14 | +class InitializeStorageClassTests(TestCase): |
| 15 | + |
| 16 | + def test_default(self): |
| 17 | + self.assertIsInstance(lazy_initialize_storage_class(), FileSystemStorage) |
| 18 | + |
| 19 | + @unittest.skipUnless(django.VERSION < (5, 1), "Test only applicable for Django versions < 5.1") |
| 20 | + @override_settings( |
| 21 | + IMPORT_EXPORT_CELERY_STORAGE="winners.tests.test_fields.FooTestingStorage" |
| 22 | + ) |
| 23 | + def test_old_style(self): |
| 24 | + del settings.IMPORT_EXPORT_CELERY_STORAGE_ALIAS |
| 25 | + del settings.STORAGES |
| 26 | + self.assertIsInstance(lazy_initialize_storage_class(), FooTestingStorage) |
| 27 | + |
| 28 | + @unittest.skipUnless((4, 2) <= django.VERSION, "Test only applicable for Django 4.2 and later") |
| 29 | + @override_settings( |
| 30 | + IMPORT_EXPORT_CELERY_STORAGE_ALIAS="test_import_export_celery", |
| 31 | + STORAGES={ |
| 32 | + "test_import_export_celery": { |
| 33 | + "BACKEND": "winners.tests.test_fields.FooTestingStorage", |
| 34 | + }, |
| 35 | + "staticfiles": { |
| 36 | + "BACKEND": "django.core.files.storage.FileSystemStorage", |
| 37 | + }, |
| 38 | + "default": { |
| 39 | + "BACKEND": "django.core.files.storage.FileSystemStorage", |
| 40 | + } |
| 41 | + } |
| 42 | +
|
| 43 | + ) |
| 44 | + def test_new_style(self): |
| 45 | + self.assertIsInstance(lazy_initialize_storage_class(), FooTestingStorage) |
| 46 | + |
| 47 | + @unittest.skipUnless((4, 2) <= django.VERSION, "Test only applicable for Django 4.2 and later") |
| 48 | + @override_settings( |
| 49 | + STORAGES={ |
| 50 | + "staticfiles": { |
| 51 | + "BACKEND": "django.core.files.storage.FileSystemStorage", |
| 52 | + }, |
| 53 | + "default": { |
| 54 | + "BACKEND": "winners.tests.test_fields.FooTestingStorage", |
| 55 | + } |
| 56 | + } |
| 57 | + ) |
| 58 | + def test_default_storage(self): |
| 59 | + """ Test that "default" storage is used when no alias is provided """ |
| 60 | + self.assertIsInstance(lazy_initialize_storage_class(), FooTestingStorage) |
0 commit comments