Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Claude Paroz authored October 27, 2012
7  django/test/signals.py
@@ -5,6 +5,7 @@
5 5
 from django.db import connections
6 6
 from django.dispatch import receiver, Signal
7 7
 from django.utils import timezone
  8
+from django.utils.functional import empty
8 9
 
9 10
 template_rendered = Signal(providing_args=["template", "context"])
10 11
 
@@ -72,3 +73,9 @@ def language_changed(**kwargs):
72 73
         trans_real._default = None
73 74
         if kwargs['setting'] == 'LOCALE_PATHS':
74 75
             trans_real._translations = {}
  76
+
  77
+@receiver(setting_changed)
  78
+def file_storage_changed(**kwargs):
  79
+    if kwargs['setting'] in ('MEDIA_ROOT', 'DEFAULT_FILE_STORAGE'):
  80
+        from django.core.files.storage import default_storage
  81
+        default_storage._wrapped = empty
19  docs/topics/testing.txt
@@ -1594,15 +1594,16 @@ callbacks to clean up and otherwise reset state when settings are changed.
1594 1594
 
1595 1595
 Django itself uses this signal to reset various data:
1596 1596
 
1597  
-=========================== ========================
1598  
-Overriden settings          Data reset
1599  
-=========================== ========================
1600  
-USE_TZ, TIME_ZONE           Databases timezone
1601  
-TEMPLATE_CONTEXT_PROCESSORS Context processors cache
1602  
-TEMPLATE_LOADERS            Template loaders cache
1603  
-SERIALIZATION_MODULES       Serializers cache
1604  
-LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
1605  
-=========================== ========================
  1597
+================================ ========================
  1598
+Overriden settings               Data reset
  1599
+================================ ========================
  1600
+USE_TZ, TIME_ZONE                Databases timezone
  1601
+TEMPLATE_CONTEXT_PROCESSORS      Context processors cache
  1602
+TEMPLATE_LOADERS                 Template loaders cache
  1603
+SERIALIZATION_MODULES            Serializers cache
  1604
+LOCALE_PATHS, LANGUAGE_CODE      Default translation and loaded translations
  1605
+MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
  1606
+================================ ========================
1606 1607
 
1607 1608
 Emptying the test outbox
1608 1609
 ~~~~~~~~~~~~~~~~~~~~~~~~
9  tests/regressiontests/staticfiles_tests/tests.py
@@ -12,7 +12,6 @@
12 12
 from django.conf import settings
13 13
 from django.core.cache.backends.base import BaseCache
14 14
 from django.core.exceptions import ImproperlyConfigured
15  
-from django.core.files.storage import default_storage
16 15
 from django.core.management import call_command
17 16
 from django.test import TestCase
18 17
 from django.test.utils import override_settings
@@ -48,10 +47,9 @@ class BaseStaticFilesTestCase(object):
48 47
     Test case with a couple utility assertions.
49 48
     """
50 49
     def setUp(self):
51  
-        # Clear the cached default_storage out, this is because when it first
52  
-        # gets accessed (by some other test), it evaluates settings.MEDIA_ROOT,
  50
+        # Clear the cached staticfiles_storage out, this is because when it first
  51
+        # gets accessed (by some other test), it evaluates settings.STATIC_ROOT,
53 52
         # since we're planning on changing that we need to clear out the cache.
54  
-        default_storage._wrapped = empty
55 53
         storage.staticfiles_storage._wrapped = empty
56 54
         # Clear the cached staticfile finders, so they are reinitialized every
57 55
         # run and pick up changes in settings.STATICFILES_DIRS.
@@ -709,9 +707,6 @@ class TestMiscFinder(TestCase):
709 707
     """
710 708
     A few misc finder tests.
711 709
     """
712  
-    def setUp(self):
713  
-        default_storage._wrapped = empty
714  
-
715 710
     def test_get_finder(self):
716 711
         self.assertIsInstance(finders.get_finder(
717 712
             'django.contrib.staticfiles.finders.FileSystemFinder'),

0 notes on commit a24ffa5

Please sign in to comment.
Something went wrong with that request. Please try again.