Ticket #17744: 17744-1.diff

File 17744-1.diff, 3.9 KB (added by claudep, 3 years ago)

Reset default storage with setting_changed

  • django/test/signals.py

    diff --git a/django/test/signals.py b/django/test/signals.py
    index d140304..a96bdff 100644
    a b from django.conf import settings 
    55from django.db import connections
    66from django.dispatch import receiver, Signal
    77from django.utils import timezone
     8from django.utils.functional import empty
    89
    910template_rendered = Signal(providing_args=["template", "context"])
    1011
    def language_changed(**kwargs): 
    7273        trans_real._default = None
    7374        if kwargs['setting'] == 'LOCALE_PATHS':
    7475            trans_real._translations = {}
     76
     77@receiver(setting_changed)
     78def 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
  • docs/topics/testing.txt

    diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
    index 7c25a8b..f5fd4fe 100644
    a b callbacks to clean up and otherwise reset state when settings are changed. 
    15941594
    15951595Django itself uses this signal to reset various data:
    15961596
    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================================ ========================
     1598Overriden settings               Data reset
     1599================================ ========================
     1600USE_TZ, TIME_ZONE                Databases timezone
     1601TEMPLATE_CONTEXT_PROCESSORS      Context processors cache
     1602TEMPLATE_LOADERS                 Template loaders cache
     1603SERIALIZATION_MODULES            Serializers cache
     1604LOCALE_PATHS, LANGUAGE_CODE      Default translation and loaded translations
     1605MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
     1606================================ ========================
    16061607
    16071608Emptying the test outbox
    16081609~~~~~~~~~~~~~~~~~~~~~~~~
  • tests/regressiontests/staticfiles_tests/tests.py

    diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
    index 7ecbccc..69e3061 100644
    a b from django.template import loader, Context 
    1212from django.conf import settings
    1313from django.core.cache.backends.base import BaseCache
    1414from django.core.exceptions import ImproperlyConfigured
    15 from django.core.files.storage import default_storage
    1615from django.core.management import call_command
    1716from django.test import TestCase
    1817from django.test.utils import override_settings
    class BaseStaticFilesTestCase(object): 
    4847    Test case with a couple utility assertions.
    4948    """
    5049    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,
    5352        # since we're planning on changing that we need to clear out the cache.
    54         default_storage._wrapped = empty
    5553        storage.staticfiles_storage._wrapped = empty
    5654        # Clear the cached staticfile finders, so they are reinitialized every
    5755        # run and pick up changes in settings.STATICFILES_DIRS.
    class TestMiscFinder(TestCase): 
    709707    """
    710708    A few misc finder tests.
    711709    """
    712     def setUp(self):
    713         default_storage._wrapped = empty
    714 
    715710    def test_get_finder(self):
    716711        self.assertIsInstance(finders.get_finder(
    717712            'django.contrib.staticfiles.finders.FileSystemFinder'),
Back to Top