diff options
| author | Ling-Xiao Yang <ling-xiao.yang@savoirfairelinux.com> | 2017-01-02 17:35:43 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-02-01 09:48:24 -0500 |
| commit | 0ec4dc91e0e7befdd06aa0613b5d0fbe3c785ee7 (patch) | |
| tree | a90c017fa9555b3cbcb7e05459a8ee6dbe66a6cd /tests/staticfiles_tests | |
| parent | ac5f886c5610a6bca26dab10170b445d1e9df450 (diff) | |
Fixed #27661 -- Moved FileSystemFinder's ImproperlyConfigured exceptions to system checks.
Thanks Simon Charette, Mariusz Felisiak, Tim Graham, and Adam Johnson
for review.
Diffstat (limited to 'tests/staticfiles_tests')
| -rw-r--r-- | tests/staticfiles_tests/test_checks.py | 77 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_finders.py | 9 |
2 files changed, 77 insertions, 9 deletions
diff --git a/tests/staticfiles_tests/test_checks.py b/tests/staticfiles_tests/test_checks.py new file mode 100644 index 0000000000..0fe432b5c7 --- /dev/null +++ b/tests/staticfiles_tests/test_checks.py @@ -0,0 +1,77 @@ +from unittest import mock + +from django.conf import settings +from django.contrib.staticfiles.checks import check_finders +from django.contrib.staticfiles.finders import BaseFinder +from django.core.checks import Error +from django.test import SimpleTestCase, override_settings + + +class FindersCheckTests(SimpleTestCase): + + def test_base_finder_check_not_implemented(self): + finder = BaseFinder() + msg = 'subclasses may provide a check() method to verify the finder is configured correctly.' + with self.assertRaisesMessage(NotImplementedError, msg): + finder.check() + + def test_check_finders(self): + """check_finders() concatenates all errors.""" + error1 = Error('1') + error2 = Error('2') + error3 = Error('3') + + def get_finders(): + class Finder1(BaseFinder): + def check(self, **kwargs): + return [error1] + + class Finder2(BaseFinder): + def check(self, **kwargs): + return [] + + class Finder3(BaseFinder): + def check(self, **kwargs): + return [error2, error3] + + class Finder4(BaseFinder): + pass + + return [Finder1(), Finder2(), Finder3(), Finder4()] + + with mock.patch('django.contrib.staticfiles.checks.get_finders', get_finders): + errors = check_finders(None) + self.assertEqual(errors, [error1, error2, error3]) + + def test_no_errors_with_test_settings(self): + self.assertEqual(check_finders(None), []) + + @override_settings(STATICFILES_DIRS='a string') + def test_dirs_not_tuple_or_list(self): + self.assertEqual(check_finders(None), [ + Error( + 'The STATICFILES_DIRS setting is not a tuple or list.', + hint='Perhaps you forgot a trailing comma?', + id='staticfiles.E001', + ) + ]) + + @override_settings(STATICFILES_DIRS=['/fake/path', settings.STATIC_ROOT]) + def test_dirs_contains_static_root(self): + self.assertEqual(check_finders(None), [ + Error( + 'The STATICFILES_DIRS setting should not contain the ' + 'STATIC_ROOT setting.', + id='staticfiles.E002', + ) + ]) + + @override_settings(STATICFILES_DIRS=[('prefix', settings.STATIC_ROOT)]) + def test_dirs_contains_static_root_in_tuple(self): + self.assertEqual(check_finders(None), [ + Error( + 'The STATICFILES_DIRS setting should not contain the ' + 'STATIC_ROOT setting.', + id='staticfiles.E002', + ) + ]) diff --git a/tests/staticfiles_tests/test_finders.py b/tests/staticfiles_tests/test_finders.py index 0b661cb103..20d3060092 100644 --- a/tests/staticfiles_tests/test_finders.py +++ b/tests/staticfiles_tests/test_finders.py @@ -103,15 +103,6 @@ class TestMiscFinder(SimpleTestCase): [os.path.join(TEST_ROOT, 'project', 'documents')] ) - @override_settings(STATICFILES_DIRS='a string') - def test_non_tuple_raises_exception(self): - """ - We can't determine if STATICFILES_DIRS is set correctly just by - looking at the type, but we can determine if it's definitely wrong. - """ - with self.assertRaises(ImproperlyConfigured): - finders.FileSystemFinder() - @override_settings(MEDIA_ROOT='') def test_location_empty(self): with self.assertRaises(ImproperlyConfigured): |
