Ticket #15094: 0001-Raise-ImproperlyConfigured-if-STATICFILES_DIRS-is-no.patch

File 0001-Raise-ImproperlyConfigured-if-STATICFILES_DIRS-is-no.patch, 2.2 KB (added by Elmar Athmer, 14 years ago)

Second attempt to fix the unexpected behavior by raising an exception.

  • django/contrib/staticfiles/finders.py

    From cd3785e232ca81dc8cfe628e6f7f147aea761483 Mon Sep 17 00:00:00 2001
    From: Elmar Athmer <elmar@nixus-minimax.de>
    Date: Mon, 31 Jan 2011 22:55:26 +0100
    Subject: [PATCH] Raise ImproperlyConfigured if STATICFILES_DIRS is not of type tuple.
    
    ---
     django/contrib/staticfiles/finders.py            |    5 +++++
     tests/regressiontests/staticfiles_tests/tests.py |   15 +++++++++++++++
     2 files changed, 20 insertions(+), 0 deletions(-)
    
    diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
    index 1ce8cdb..42606fd 100644
    a b class FileSystemFinder(BaseFinder):  
    4747        self.storages = SortedDict()
    4848        # Set of locations with static files
    4949        self.locations = set()
     50
     51        if not type(settings.STATICFILES_DIRS) == tuple:
     52            raise ImproperlyConfigured("STATICFILES_DIRS has to be of type "
     53                "tuple, but is %s." % type(settings.STATICFILES_DIRS))
     54
    5055        for root in settings.STATICFILES_DIRS:
    5156            if isinstance(root, (list, tuple)):
    5257                prefix, root = root
  • tests/regressiontests/staticfiles_tests/tests.py

    diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
    index ea1f6d2..2afd2e4 100644
    a b class TestMiscFinder(TestCase):  
    387387            finders.get_finder, 'django.contrib.staticfiles.finders.FooBarFinder')
    388388        self.assertRaises(ImproperlyConfigured,
    389389            finders.get_finder, 'foo.bar.FooBarFinder')
     390
     391class TestStaticfilesDirsType(TestCase):
     392    """
     393    We can't determine if STATICFILES_DIRS is set correctly just by looking at
     394    the type, but we can determine if it's definitely wrong.
     395    """
     396    def setUp(self):
     397        self.old_settings_dir = settings.STATICFILES_DIRS
     398        settings.STATICFILES_DIRS = 'a string'
     399
     400    def tearDown(self):
     401        settings.STATICFILES_DIRS = self.old_settings_dir
     402
     403    def test_non_tuple_raises_exception(self):
     404        self.assertRaises(ImproperlyConfigured, finders.FileSystemFinder)
     405 No newline at end of file
Back to Top