diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py index 80ec9e3c48a8..96eb7e71ddbb 100644 --- a/django/contrib/staticfiles/finders.py +++ b/django/contrib/staticfiles/finders.py @@ -26,6 +26,17 @@ def check(self, **kwargs): "configured correctly." ) + def find(self, path, find_all=False): + """ + Given a relative file path, find an absolute file path. + + If the ``find_all`` parameter is False (default) return only the first + found file path; if True, return a list of all found files paths. + """ + raise NotImplementedError( + "subclasses of BaseFinder must provide a find() method" + ) + def list(self, ignore_patterns): """ Given an optional list of paths to ignore, return a two item iterable diff --git a/tests/staticfiles_tests/test_finders.py b/tests/staticfiles_tests/test_finders.py index 7efe86ab6a08..7ab3cd035082 100644 --- a/tests/staticfiles_tests/test_finders.py +++ b/tests/staticfiles_tests/test_finders.py @@ -9,6 +9,20 @@ from .settings import TEST_ROOT +class TestBaseFinder(SimpleTestCase): + def test_find(self): + finder = finders.BaseFinder() + msg = "subclasses of BaseFinder must provide a find() method" + with self.assertRaisesMessage(NotImplementedError, msg): + finder.find("file.txt") + + def test_list(self): + finder = finders.BaseFinder() + msg = "subclasses of BaseFinder must provide a list() method" + with self.assertRaisesMessage(NotImplementedError, msg): + finder.list(None) + + class TestFinders: """ Base finder test mixin.