diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-15 05:58:54 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-09-18 22:12:40 +0200 |
| commit | f72f420f17c1bf6aea4022ecdb9b5f53a46597cc (patch) | |
| tree | bcba9c795159eb40ae916ce520a25c9e9d796ecf /tests | |
| parent | 3a3e737694b89e29308e54f12faaa375226b7060 (diff) | |
Refs #26029 -- Removed DEFAULT_FILE_STORAGE and STATICFILES_STORAGE settings.
This also removes django.core.files.storage.get_storage_class().
Per deprecation timeline.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/deprecation/test_storages.py | 262 | ||||
| -rw-r--r-- | tests/file_storage/tests.py | 61 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_checks.py | 15 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_management.py | 15 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_storage.py | 8 |
5 files changed, 23 insertions, 338 deletions
diff --git a/tests/deprecation/test_storages.py b/tests/deprecation/test_storages.py deleted file mode 100644 index 99a1fc1884..0000000000 --- a/tests/deprecation/test_storages.py +++ /dev/null @@ -1,262 +0,0 @@ -import sys -from types import ModuleType - -from django.conf import ( - DEFAULT_FILE_STORAGE_DEPRECATED_MSG, - DEFAULT_STORAGE_ALIAS, - STATICFILES_STORAGE_ALIAS, - STATICFILES_STORAGE_DEPRECATED_MSG, - Settings, - settings, -) -from django.contrib.staticfiles.storage import ( - ManifestStaticFilesStorage, - staticfiles_storage, -) -from django.core.exceptions import ImproperlyConfigured -from django.core.files.storage import Storage, StorageHandler, default_storage, storages -from django.test import TestCase, ignore_warnings -from django.utils.deprecation import RemovedInDjango51Warning - - -class StaticfilesStorageDeprecationTests(TestCase): - msg = STATICFILES_STORAGE_DEPRECATED_MSG - - def test_override_settings_warning(self): - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - with self.settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - ): - pass - - def test_settings_init(self): - old_staticfiles_storage = settings.STORAGES.get(STATICFILES_STORAGE_ALIAS) - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.STATICFILES_STORAGE = ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - sys.modules["fake_settings_module"] = settings_module - try: - with self.assertWarnsMessage(RemovedInDjango51Warning, self.msg): - fake_settings = Settings("fake_settings_module") - self.assertEqual( - fake_settings.STORAGES[STATICFILES_STORAGE_ALIAS], - { - "BACKEND": ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ), - }, - ) - # settings.STORAGES is not mutated. - self.assertEqual( - settings.STORAGES.get(STATICFILES_STORAGE_ALIAS), - old_staticfiles_storage, - ) - finally: - del sys.modules["fake_settings_module"] - - def test_settings_storages_init(self): - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.STORAGES = { - STATICFILES_STORAGE_ALIAS: { - "BACKEND": ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - } - } - sys.modules["fake_settings_module"] = settings_module - try: - fake_settings = Settings("fake_settings_module") - self.assertEqual( - fake_settings.STATICFILES_STORAGE, - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", - ) - finally: - del sys.modules["fake_settings_module"] - - def test_access_warning(self): - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - settings.STATICFILES_STORAGE - # Works a second time. - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - settings.STATICFILES_STORAGE - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_access(self): - with self.settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - ): - self.assertEqual( - settings.STATICFILES_STORAGE, - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", - ) - # Works a second time. - self.assertEqual( - settings.STATICFILES_STORAGE, - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", - ) - - def test_use_both_error(self): - msg = "STATICFILES_STORAGE/STORAGES are mutually exclusive." - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.STATICFILES_STORAGE = ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - settings_module.STORAGES = {} - sys.modules["fake_settings_module"] = settings_module - try: - with self.assertRaisesMessage(ImproperlyConfigured, msg): - Settings("fake_settings_module") - finally: - del sys.modules["fake_settings_module"] - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_storage(self): - empty_storages = StorageHandler() - with self.settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - ): - self.assertIsInstance( - storages[STATICFILES_STORAGE_ALIAS], - ManifestStaticFilesStorage, - ) - self.assertIsInstance( - empty_storages[STATICFILES_STORAGE_ALIAS], - ManifestStaticFilesStorage, - ) - self.assertIsInstance(staticfiles_storage, ManifestStaticFilesStorage) - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_staticfiles_storage(self): - with self.settings( - STORAGES={ - STATICFILES_STORAGE_ALIAS: { - "BACKEND": ( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) - } - } - ): - self.assertEqual( - settings.STATICFILES_STORAGE, - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", - ) - self.assertIsInstance( - storages[STATICFILES_STORAGE_ALIAS], - ManifestStaticFilesStorage, - ) - - -class DefaultStorageDeprecationTests(TestCase): - msg = DEFAULT_FILE_STORAGE_DEPRECATED_MSG - - def test_override_settings_warning(self): - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - with self.settings( - DEFAULT_FILE_STORAGE=("django.core.files.storage.Storage") - ): - pass - - def test_settings_init(self): - old_default_storage = settings.STORAGES.get(DEFAULT_STORAGE_ALIAS) - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.DEFAULT_FILE_STORAGE = "django.core.files.storage.Storage" - sys.modules["fake_settings_module"] = settings_module - try: - with self.assertWarnsMessage(RemovedInDjango51Warning, self.msg): - fake_settings = Settings("fake_settings_module") - self.assertEqual( - fake_settings.STORAGES[DEFAULT_STORAGE_ALIAS], - {"BACKEND": "django.core.files.storage.Storage"}, - ) - # settings.STORAGES is not mutated. - self.assertEqual( - settings.STORAGES.get(DEFAULT_STORAGE_ALIAS), - old_default_storage, - ) - finally: - del sys.modules["fake_settings_module"] - - def test_settings_storages_init(self): - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.STORAGES = { - DEFAULT_STORAGE_ALIAS: { - "BACKEND": "django.core.files.storage.Storage", - } - } - sys.modules["fake_settings_module"] = settings_module - try: - fake_settings = Settings("fake_settings_module") - self.assertEqual( - fake_settings.DEFAULT_FILE_STORAGE, - "django.core.files.storage.Storage", - ) - finally: - del sys.modules["fake_settings_module"] - - def test_access_warning(self): - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - settings.DEFAULT_FILE_STORAGE - # Works a second time. - with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg): - settings.DEFAULT_FILE_STORAGE - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_access(self): - with self.settings(DEFAULT_FILE_STORAGE="django.core.files.storage.Storage"): - self.assertEqual( - settings.DEFAULT_FILE_STORAGE, - "django.core.files.storage.Storage", - ) - # Works a second time. - self.assertEqual( - settings.DEFAULT_FILE_STORAGE, - "django.core.files.storage.Storage", - ) - - def test_use_both_error(self): - msg = "DEFAULT_FILE_STORAGE/STORAGES are mutually exclusive." - settings_module = ModuleType("fake_settings_module") - settings_module.USE_TZ = True - settings_module.DEFAULT_FILE_STORAGE = "django.core.files.storage.Storage" - settings_module.STORAGES = {} - sys.modules["fake_settings_module"] = settings_module - try: - with self.assertRaisesMessage(ImproperlyConfigured, msg): - Settings("fake_settings_module") - finally: - del sys.modules["fake_settings_module"] - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_storage(self): - empty_storages = StorageHandler() - with self.settings(DEFAULT_FILE_STORAGE="django.core.files.storage.Storage"): - self.assertIsInstance(storages[DEFAULT_STORAGE_ALIAS], Storage) - self.assertIsInstance(empty_storages[DEFAULT_STORAGE_ALIAS], Storage) - self.assertIsInstance(default_storage, Storage) - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_default_file_storage(self): - with self.settings( - STORAGES={ - DEFAULT_STORAGE_ALIAS: { - "BACKEND": "django.core.files.storage.Storage", - } - } - ): - self.assertEqual( - settings.DEFAULT_FILE_STORAGE, - "django.core.files.storage.Storage", - ) - self.assertIsInstance(storages[DEFAULT_STORAGE_ALIAS], Storage) diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 6ff56ae169..8c47e43742 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -15,18 +15,9 @@ from django.conf import DEFAULT_STORAGE_ALIAS, STATICFILES_STORAGE_ALIAS from django.core.cache import cache from django.core.exceptions import SuspiciousFileOperation from django.core.files.base import ContentFile, File -from django.core.files.storage import ( - GET_STORAGE_CLASS_DEPRECATED_MSG, - FileSystemStorage, - InvalidStorageError, -) +from django.core.files.storage import FileSystemStorage, InvalidStorageError from django.core.files.storage import Storage as BaseStorage -from django.core.files.storage import ( - StorageHandler, - default_storage, - get_storage_class, - storages, -) +from django.core.files.storage import StorageHandler, default_storage, storages from django.core.files.uploadedfile import ( InMemoryUploadedFile, SimpleUploadedFile, @@ -35,11 +26,10 @@ from django.core.files.uploadedfile import ( from django.db.models import FileField from django.db.models.fields.files import FileDescriptor from django.test import LiveServerTestCase, SimpleTestCase, TestCase, override_settings -from django.test.utils import ignore_warnings, requires_tz_support +from django.test.utils import requires_tz_support from django.urls import NoReverseMatch, reverse_lazy from django.utils import timezone from django.utils._os import symlinks_supported -from django.utils.deprecation import RemovedInDjango51Warning from .models import ( Storage, @@ -52,51 +42,6 @@ from .models import ( FILE_SUFFIX_REGEX = "[A-Za-z0-9]{7}" -class GetStorageClassTests(SimpleTestCase): - @ignore_warnings(category=RemovedInDjango51Warning) - def test_get_filesystem_storage(self): - """ - get_storage_class returns the class for a storage backend name/path. - """ - self.assertEqual( - get_storage_class("django.core.files.storage.FileSystemStorage"), - FileSystemStorage, - ) - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_get_invalid_storage_module(self): - """ - get_storage_class raises an error if the requested import don't exist. - """ - with self.assertRaisesMessage(ImportError, "No module named 'storage'"): - get_storage_class("storage.NonexistentStorage") - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_get_nonexistent_storage_class(self): - """ - get_storage_class raises an error if the requested class don't exist. - """ - with self.assertRaises(ImportError): - get_storage_class("django.core.files.storage.NonexistentStorage") - - @ignore_warnings(category=RemovedInDjango51Warning) - def test_get_nonexistent_storage_module(self): - """ - get_storage_class raises an error if the requested module don't exist. - """ - with self.assertRaisesMessage( - ImportError, "No module named 'django.core.files.nonexistent_storage'" - ): - get_storage_class( - "django.core.files.nonexistent_storage.NonexistentStorage" - ) - - def test_deprecation_warning(self): - msg = GET_STORAGE_CLASS_DEPRECATED_MSG - with self.assertRaisesMessage(RemovedInDjango51Warning, msg): - get_storage_class("django.core.files.storage.FileSystemStorage") - - class FileSystemStorageTests(unittest.TestCase): def test_deconstruction(self): path, args, kwargs = temp_storage.deconstruct() diff --git a/tests/staticfiles_tests/test_checks.py b/tests/staticfiles_tests/test_checks.py index 14f72ef357..b9ac486ed1 100644 --- a/tests/staticfiles_tests/test_checks.py +++ b/tests/staticfiles_tests/test_checks.py @@ -137,11 +137,6 @@ class FindersCheckTests(CollectionTestCase): class StoragesCheckTests(SimpleTestCase): @override_settings(STORAGES={}) def test_error_empty_storages(self): - # DEFAULT_STORAGE_ALIAS and STATICFILES_STORAGE_ALIAS need to be - # popped from STORAGES since UserSettingsHolder has code to maintain - # backward compatibility until 5.1 is out. - settings.STORAGES.clear() # RemovedInDjango51Warning - assert settings.STORAGES == {} # RemovedInDjango51Warning errors = check_storages(None) self.assertEqual(errors, [E005]) @@ -156,11 +151,6 @@ class StoragesCheckTests(SimpleTestCase): } ) def test_error_missing_staticfiles(self): - # Check out the previous comment about UserSettingsHolder compat code. - settings.STORAGES.pop(STATICFILES_STORAGE_ALIAS) # RemovedInDjango51Warning - assert ( - STATICFILES_STORAGE_ALIAS not in settings.STORAGES - ) # RemovedInDjango51Warning errors = check_storages(None) self.assertEqual(errors, [E005]) @@ -172,10 +162,5 @@ class StoragesCheckTests(SimpleTestCase): } ) def test_staticfiles_no_errors(self): - # Check out the previous comment about UserSettingsHolder compat code. - settings.STORAGES.pop(DEFAULT_STORAGE_ALIAS) # RemovedInDjango51Warning - assert ( - DEFAULT_STORAGE_ALIAS not in settings.STORAGES - ) # RemovedInDjango51Warning errors = check_storages(None) self.assertEqual(errors, []) diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 8398195cec..46e6f3e764 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -142,11 +142,12 @@ class TestConfiguration(StaticFilesTestCase): storage.staticfiles_storage._wrapped = empty with self.settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": ( "django.contrib.staticfiles.storage.StaticFilesStorage" ) - } + }, } ): command = collectstatic.Command() @@ -155,9 +156,10 @@ class TestConfiguration(StaticFilesTestCase): storage.staticfiles_storage._wrapped = empty with self.settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.DummyStorage" - } + }, } ): command = collectstatic.Command() @@ -250,6 +252,7 @@ class TestCollectionVerbosity(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": ( "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" @@ -264,6 +267,7 @@ class TestCollectionVerbosity(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": ( "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" @@ -297,6 +301,7 @@ class TestCollectionClear(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.PathNotImplementedStorage" }, @@ -416,6 +421,7 @@ class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" }, @@ -544,6 +550,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.DummyStorage" }, @@ -571,6 +578,7 @@ class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase): class TestCollectionNeverCopyStorage(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.NeverCopyRemoteStorage" }, @@ -642,9 +650,10 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.PathNotImplementedStorage" - } + }, } ) def test_no_remote_link(self): diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index dc8607a307..ea2293ccde 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -361,6 +361,7 @@ class TestHashedFiles: @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.ExtraPatternsStorage", }, @@ -396,6 +397,7 @@ class TestExtraPatternsStorage(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", }, @@ -561,6 +563,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.NoneHashStorage", }, @@ -576,6 +579,7 @@ class TestCollectionNoneHashStorage(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.NoPostProcessReplacedPathStorage", }, @@ -592,6 +596,7 @@ class TestCollectionNoPostProcessReplacedPaths(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.storage.SimpleStorage", }, @@ -630,6 +635,7 @@ class JSModuleImportAggregationManifestStorage(storage.ManifestStaticFilesStorag @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": ( "staticfiles_tests.test_storage." @@ -811,6 +817,7 @@ class TestStaticFilePermissions(CollectionTestCase): FILE_UPLOAD_PERMISSIONS=0o655, FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o765, STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "staticfiles_tests.test_storage.CustomStaticFilesStorage", }, @@ -835,6 +842,7 @@ class TestStaticFilePermissions(CollectionTestCase): @override_settings( STORAGES={ + **settings.STORAGES, STATICFILES_STORAGE_ALIAS: { "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", }, |
