Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.5.x] Fixed #17744 -- Reset default file storage with setting_chang…

…ed signal

Backport of 9a02851 from master.
  • Loading branch information...
commit a24ffa52d02998f5082fbc5a461ccdc8004db4a6 1 parent 5229ac2
@claudep claudep authored
View
7 django/test/signals.py
@@ -5,6 +5,7 @@
from django.db import connections
from django.dispatch import receiver, Signal
from django.utils import timezone
+from django.utils.functional import empty
template_rendered = Signal(providing_args=["template", "context"])
@@ -72,3 +73,9 @@ def language_changed(**kwargs):
trans_real._default = None
if kwargs['setting'] == 'LOCALE_PATHS':
trans_real._translations = {}
+
+@receiver(setting_changed)
+def file_storage_changed(**kwargs):
+ if kwargs['setting'] in ('MEDIA_ROOT', 'DEFAULT_FILE_STORAGE'):
+ from django.core.files.storage import default_storage
+ default_storage._wrapped = empty
View
19 docs/topics/testing.txt
@@ -1594,15 +1594,16 @@ callbacks to clean up and otherwise reset state when settings are changed.
Django itself uses this signal to reset various data:
-=========================== ========================
-Overriden settings Data reset
-=========================== ========================
-USE_TZ, TIME_ZONE Databases timezone
-TEMPLATE_CONTEXT_PROCESSORS Context processors cache
-TEMPLATE_LOADERS Template loaders cache
-SERIALIZATION_MODULES Serializers cache
-LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
-=========================== ========================
+================================ ========================
+Overriden settings Data reset
+================================ ========================
+USE_TZ, TIME_ZONE Databases timezone
+TEMPLATE_CONTEXT_PROCESSORS Context processors cache
+TEMPLATE_LOADERS Template loaders cache
+SERIALIZATION_MODULES Serializers cache
+LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
+MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
+================================ ========================
Emptying the test outbox
~~~~~~~~~~~~~~~~~~~~~~~~
View
9 tests/regressiontests/staticfiles_tests/tests.py
@@ -12,7 +12,6 @@
from django.conf import settings
from django.core.cache.backends.base import BaseCache
from django.core.exceptions import ImproperlyConfigured
-from django.core.files.storage import default_storage
from django.core.management import call_command
from django.test import TestCase
from django.test.utils import override_settings
@@ -48,10 +47,9 @@ class BaseStaticFilesTestCase(object):
Test case with a couple utility assertions.
"""
def setUp(self):
- # Clear the cached default_storage out, this is because when it first
- # gets accessed (by some other test), it evaluates settings.MEDIA_ROOT,
+ # Clear the cached staticfiles_storage out, this is because when it first
+ # gets accessed (by some other test), it evaluates settings.STATIC_ROOT,
# since we're planning on changing that we need to clear out the cache.
- default_storage._wrapped = empty
storage.staticfiles_storage._wrapped = empty
# Clear the cached staticfile finders, so they are reinitialized every
# run and pick up changes in settings.STATICFILES_DIRS.
@@ -709,9 +707,6 @@ class TestMiscFinder(TestCase):
"""
A few misc finder tests.
"""
- def setUp(self):
- default_storage._wrapped = empty
-
def test_get_finder(self):
self.assertIsInstance(finders.get_finder(
'django.contrib.staticfiles.finders.FileSystemFinder'),
Please sign in to comment.
Something went wrong with that request. Please try again.