diff options
author | Jarosław Wygoda <jaroslaw@wygoda.me> | 2022-09-11 17:33:47 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-12 09:58:36 +0100 |
commit | 32940d390a00a30a6409282d314d617667892841 (patch) | |
tree | 3912c57c1b553833a8a798d92a33147fb87b3f0b /tests/staticfiles_tests | |
parent | 1ec3f0961fedbe01f174b78ef2805a9d4f3844b1 (diff) | |
download | django-32940d390a00a30a6409282d314d617667892841.tar.gz |
Refs #26029 -- Deprecated DEFAULT_FILE_STORAGE and STATICFILES_STORAGE settings.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/test_forms.py | 9 | ||||
-rw-r--r-- | tests/staticfiles_tests/test_management.py | 70 | ||||
-rw-r--r-- | tests/staticfiles_tests/test_storage.py | 50 | ||||
-rw-r--r-- | tests/staticfiles_tests/test_templatetags.py | 7 |
4 files changed, 109 insertions, 27 deletions
diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py index ad662d7321..489140a62c 100644 --- a/tests/staticfiles_tests/test_forms.py +++ b/tests/staticfiles_tests/test_forms.py @@ -1,5 +1,6 @@ from urllib.parse import urljoin +from django.conf import STATICFILES_STORAGE_ALIAS from django.contrib.staticfiles import storage from django.forms import Media from django.templatetags.static import static @@ -12,9 +13,13 @@ class StaticTestStorage(storage.StaticFilesStorage): @override_settings( - STATIC_URL="http://media.example.com/static/", INSTALLED_APPS=("django.contrib.staticfiles",), - STATICFILES_STORAGE="staticfiles_tests.test_forms.StaticTestStorage", + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.test_forms.StaticTestStorage", + "OPTIONS": {"location": "http://media.example.com/static/"}, + } + }, ) class StaticFilesFormsMediaTestCase(SimpleTestCase): def test_absolute_url(self): diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 6dec3a67bd..8398195cec 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -9,7 +9,7 @@ from unittest import mock from admin_scripts.tests import AdminScriptTestCase -from django.conf import settings +from django.conf import STATICFILES_STORAGE_ALIAS, settings from django.contrib.staticfiles import storage from django.contrib.staticfiles.management.commands import collectstatic, runserver from django.core.exceptions import ImproperlyConfigured @@ -141,16 +141,24 @@ class TestConfiguration(StaticFilesTestCase): try: storage.staticfiles_storage._wrapped = empty with self.settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.StaticFilesStorage" - ) + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": ( + "django.contrib.staticfiles.storage.StaticFilesStorage" + ) + } + } ): command = collectstatic.Command() self.assertTrue(command.is_local_storage()) storage.staticfiles_storage._wrapped = empty with self.settings( - STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.DummyStorage" + } + } ): command = collectstatic.Command() self.assertFalse(command.is_local_storage()) @@ -241,9 +249,13 @@ class TestCollectionVerbosity(CollectionTestCase): self.assertIn(self.copying_msg, output) @override_settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": ( + "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" + ) + }, + } ) def test_verbosity_1_with_post_process(self): stdout = StringIO() @@ -251,9 +263,13 @@ class TestCollectionVerbosity(CollectionTestCase): self.assertNotIn(self.post_process_msg, stdout.getvalue()) @override_settings( - STATICFILES_STORAGE=( - "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" - ) + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": ( + "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" + ) + }, + } ) def test_verbosity_2_with_post_process(self): stdout = StringIO() @@ -280,7 +296,11 @@ class TestCollectionClear(CollectionTestCase): super().run_collectstatic(clear=True) @override_settings( - STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.PathNotImplementedStorage" + }, + } ) def test_handle_path_notimplemented(self): self.run_collectstatic() @@ -395,7 +415,11 @@ class TestCollectionDryRun(TestNoFilesCreated, CollectionTestCase): @override_settings( - STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" + }, + } ) class TestCollectionDryRunManifestStaticFilesStorage(TestCollectionDryRun): pass @@ -518,7 +542,13 @@ class TestCollectionOverwriteWarning(CollectionTestCase): self.assertNotIn(self.warning_string, output) -@override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.DummyStorage") +@override_settings( + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.DummyStorage" + }, + } +) class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase): """ Tests for a Storage that implements get_modified_time() but not path() @@ -540,7 +570,11 @@ class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase): class TestCollectionNeverCopyStorage(CollectionTestCase): @override_settings( - STATICFILES_STORAGE="staticfiles_tests.storage.NeverCopyRemoteStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.NeverCopyRemoteStorage" + }, + } ) def test_skips_newer_files_in_remote_storage(self): """ @@ -607,7 +641,11 @@ class TestCollectionLinks(TestDefaults, CollectionTestCase): self.assertFalse(os.path.lexists(broken_symlink_path)) @override_settings( - STATICFILES_STORAGE="staticfiles_tests.storage.PathNotImplementedStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.PathNotImplementedStorage" + } + } ) def test_no_remote_link(self): with self.assertRaisesMessage( diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index f2f1899aac..11b160945e 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -8,7 +8,7 @@ from io import StringIO from pathlib import Path from unittest import mock -from django.conf import settings +from django.conf import STATICFILES_STORAGE_ALIAS, settings from django.contrib.staticfiles import finders, storage from django.contrib.staticfiles.management.commands.collectstatic import ( Command as CollectstaticCommand, @@ -369,7 +369,13 @@ class TestHashedFiles: self.assertPostCondition() -@override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.ExtraPatternsStorage") +@override_settings( + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.ExtraPatternsStorage", + }, + } +) class TestExtraPatternsStorage(CollectionTestCase): def setUp(self): storage.staticfiles_storage.hashed_files.clear() # avoid cache interference @@ -399,7 +405,11 @@ class TestExtraPatternsStorage(CollectionTestCase): @override_settings( - STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage", + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", + }, + } ) class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): """ @@ -559,7 +569,13 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase): self.assertEqual(manifest_content, {"dummy.txt": "dummy.txt"}) -@override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.NoneHashStorage") +@override_settings( + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.NoneHashStorage", + }, + } +) class TestCollectionNoneHashStorage(CollectionTestCase): hashed_file_path = hashed_file_path @@ -569,7 +585,11 @@ class TestCollectionNoneHashStorage(CollectionTestCase): @override_settings( - STATICFILES_STORAGE="staticfiles_tests.storage.NoPostProcessReplacedPathStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.NoPostProcessReplacedPathStorage", + }, + } ) class TestCollectionNoPostProcessReplacedPaths(CollectionTestCase): run_collectstatic_in_setUp = False @@ -580,7 +600,13 @@ class TestCollectionNoPostProcessReplacedPaths(CollectionTestCase): self.assertIn("post-processed", stdout.getvalue()) -@override_settings(STATICFILES_STORAGE="staticfiles_tests.storage.SimpleStorage") +@override_settings( + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.SimpleStorage", + }, + } +) class TestCollectionSimpleStorage(CollectionTestCase): hashed_file_path = hashed_file_path @@ -733,7 +759,11 @@ class TestStaticFilePermissions(CollectionTestCase): @override_settings( FILE_UPLOAD_PERMISSIONS=0o655, FILE_UPLOAD_DIRECTORY_PERMISSIONS=0o765, - STATICFILES_STORAGE="staticfiles_tests.test_storage.CustomStaticFilesStorage", + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.test_storage.CustomStaticFilesStorage", + }, + }, ) def test_collect_static_files_subclass_of_static_storage(self): call_command("collectstatic", **self.command_params) @@ -753,7 +783,11 @@ class TestStaticFilePermissions(CollectionTestCase): @override_settings( - STATICFILES_STORAGE="django.contrib.staticfiles.storage.ManifestStaticFilesStorage", + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", + }, + } ) class TestCollectionHashedFilesCache(CollectionTestCase): """ diff --git a/tests/staticfiles_tests/test_templatetags.py b/tests/staticfiles_tests/test_templatetags.py index 4cc3f95ab1..9b8bcf1938 100644 --- a/tests/staticfiles_tests/test_templatetags.py +++ b/tests/staticfiles_tests/test_templatetags.py @@ -1,3 +1,4 @@ +from django.conf import STATICFILES_STORAGE_ALIAS from django.test import override_settings from .cases import StaticFilesTestCase @@ -12,7 +13,11 @@ class TestTemplateTag(StaticFilesTestCase): ) @override_settings( - STATICFILES_STORAGE="staticfiles_tests.storage.QueryStringStorage" + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": "staticfiles_tests.storage.QueryStringStorage" + }, + } ) def test_template_tag_escapes(self): """ |