Skip to content

Commit

Permalink
Fixed #17744 -- Reset default file storage with setting_changed signal
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Oct 30, 2012
1 parent 43d7cee commit 9a02851
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
7 changes: 7 additions & 0 deletions django/test/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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
19 changes: 10 additions & 9 deletions docs/topics/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
9 changes: 2 additions & 7 deletions tests/regressiontests/staticfiles_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 9a02851

Please sign in to comment.