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):
|
47 | 47 | self.storages = SortedDict() |
48 | 48 | # Set of locations with static files |
49 | 49 | 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 | |
50 | 55 | for root in settings.STATICFILES_DIRS: |
51 | 56 | if isinstance(root, (list, tuple)): |
52 | 57 | prefix, root = root |
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):
|
387 | 387 | finders.get_finder, 'django.contrib.staticfiles.finders.FooBarFinder') |
388 | 388 | self.assertRaises(ImproperlyConfigured, |
389 | 389 | finders.get_finder, 'foo.bar.FooBarFinder') |
| 390 | |
| 391 | class 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 |