Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
    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])
Ejemplo n.º 3
0
 def test_nonexistent_directories(self):
     with self.settings(
         STATICFILES_DIRS=[
             "/fake/path",
             ("prefix", "/fake/prefixed/path"),
         ]
     ):
         self.assertEqual(
             check_finders(None),
             [
                 Warning(
                     "The directory '/fake/path' in the STATICFILES_DIRS "
                     "setting does not exist.",
                     id="staticfiles.W004",
                 ),
                 Warning(
                     "The directory '/fake/prefixed/path' in the "
                     "STATICFILES_DIRS setting does not exist.",
                     id="staticfiles.W004",
                 ),
             ],
         )
         # Nonexistent directories are skipped.
         finder = get_finder("django.contrib.staticfiles.finders.FileSystemFinder")
         self.assertEqual(list(finder.list(None)), [])
Ejemplo n.º 4
0
 def test_prefix_contains_trailing_slash(self):
     self.assertEqual(check_finders(None), [
         Error(
             "The prefix 'prefix/' in the STATICFILES_DIRS setting must "
             "not end with a slash.",
             id='staticfiles.E003',
         )
     ])
Ejemplo n.º 5
0
 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',
         )
     ])
Ejemplo n.º 6
0
 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',
         )
     ])
Ejemplo n.º 7
0
 def test_prefix_contains_trailing_slash(self):
     self.assertEqual(check_finders(None), [
         Error(
             "The prefix 'prefix/' in the STATICFILES_DIRS setting must "
             "not end with a slash.",
             id='staticfiles.E003',
         )
     ])
Ejemplo n.º 8
0
 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',
         )
     ])
Ejemplo n.º 9
0
 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',
         )
     ])
Ejemplo n.º 10
0
 def test_prefix_contains_trailing_slash(self):
     static_dir = Path(TEST_ROOT) / 'project' / 'documents'
     with self.settings(STATICFILES_DIRS=[('prefix/', static_dir)]):
         self.assertEqual(check_finders(None), [
             Error(
                 "The prefix 'prefix/' in the STATICFILES_DIRS setting must "
                 "not end with a slash.",
                 id='staticfiles.E003',
             ),
         ])
Ejemplo n.º 11
0
 def test_dirs_contains_static_root_in_tuple(self):
     with self.settings(STATICFILES_DIRS=[("prefix", settings.STATIC_ROOT)]):
         self.assertEqual(
             check_finders(None),
             [
                 Error(
                     "The STATICFILES_DIRS setting should not contain the "
                     "STATIC_ROOT setting.",
                     id="staticfiles.E002",
                 )
             ],
         )
Ejemplo n.º 12
0
 def test_no_errors_with_test_settings(self):
     self.assertEqual(check_finders(None), [])
Ejemplo n.º 13
0
 def test_no_errors_with_test_settings(self):
     self.assertEqual(check_finders(None), [])