summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-18 18:11:24 +0200
committerGitHub <noreply@github.com>2023-08-18 18:11:24 +0200
commit6b965c600054f970bdf94017ecf2e0e6e0a4326b (patch)
treec936a01a0dee84314d7fe6b71b687dea25f6b51e /tests
parentd25f3892114466d689fd6936f79f3bd9a9acc30e (diff)
Fixed #34773 -- Fixed syncing DEFAULT_FILE_STORAGE/STATICFILES_STORAGE settings with STORAGES.
Thanks Petr DlouhĂ˝ for the report. Bug in 32940d390a00a30a6409282d314d617667892841.
Diffstat (limited to 'tests')
-rw-r--r--tests/deprecation/test_storages.py93
1 files changed, 89 insertions, 4 deletions
diff --git a/tests/deprecation/test_storages.py b/tests/deprecation/test_storages.py
index 71ed3acdb0..0574f3e880 100644
--- a/tests/deprecation/test_storages.py
+++ b/tests/deprecation/test_storages.py
@@ -39,8 +39,36 @@ class StaticfilesStorageDeprecationTests(TestCase):
)
sys.modules["fake_settings_module"] = settings_module
try:
- with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg):
- Settings("fake_settings_module")
+ 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"
+ ),
+ },
+ )
+ 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"]
@@ -101,6 +129,26 @@ class StaticfilesStorageDeprecationTests(TestCase):
)
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
@@ -118,8 +166,30 @@ class DefaultStorageDeprecationTests(TestCase):
settings_module.DEFAULT_FILE_STORAGE = "django.core.files.storage.Storage"
sys.modules["fake_settings_module"] = settings_module
try:
- with self.assertRaisesMessage(RemovedInDjango51Warning, self.msg):
- Settings("fake_settings_module")
+ 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"},
+ )
+ 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"]
@@ -163,3 +233,18 @@ class DefaultStorageDeprecationTests(TestCase):
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)