summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/test_finders.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/staticfiles_tests/test_finders.py')
-rw-r--r--tests/staticfiles_tests/test_finders.py82
1 files changed, 81 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/test_finders.py b/tests/staticfiles_tests/test_finders.py
index 9f2509d533..28870e6fbe 100644
--- a/tests/staticfiles_tests/test_finders.py
+++ b/tests/staticfiles_tests/test_finders.py
@@ -4,10 +4,15 @@ from django.conf import settings
from django.contrib.staticfiles import finders, storage
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase, override_settings
+from django.utils.deprecation import RemovedInDjango60Warning
from .cases import StaticFilesTestCase
from .settings import TEST_ROOT
+DEPRECATION_MSG = (
+ "Passing the `all` argument to find() is deprecated. Use `find_all` instead."
+)
+
class TestFinders:
"""
@@ -25,11 +30,49 @@ class TestFinders:
def test_find_all(self):
src, dst = self.find_all
- found = self.finder.find(src, all=True)
+ found = self.finder.find(src, find_all=True)
found = [os.path.normcase(f) for f in found]
dst = [os.path.normcase(d) for d in dst]
self.assertEqual(found, dst)
+ def test_find_all_deprecated_param(self):
+ src, dst = self.find_all
+ with self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG):
+ found = self.finder.find(src, all=True)
+ found = [os.path.normcase(f) for f in found]
+ dst = [os.path.normcase(d) for d in dst]
+ self.assertEqual(found, dst)
+
+ def test_find_all_conflicting_params(self):
+ src, dst = self.find_all
+ msg = (
+ f"{self.finder.__class__.__qualname__}.find() got multiple values for "
+ "argument 'find_all'"
+ )
+ with (
+ self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ self.finder.find(src, find_all=True, all=True)
+
+ def test_find_all_unexpected_params(self):
+ src, dst = self.find_all
+ msg = (
+ f"{self.finder.__class__.__qualname__}.find() got an unexpected keyword "
+ "argument 'wrong'"
+ )
+ with (
+ self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ self.finder.find(src, all=True, wrong=1)
+
+ with self.assertRaisesMessage(TypeError, msg):
+ self.finder.find(src, find_all=True, wrong=1)
+
+ with self.assertRaisesMessage(TypeError, msg):
+ self.finder.find(src, wrong=1)
+
class TestFileSystemFinder(TestFinders, StaticFilesTestCase):
"""
@@ -114,6 +157,43 @@ class TestMiscFinder(SimpleTestCase):
[os.path.join(TEST_ROOT, "project", "documents")],
)
+ def test_searched_locations_find_all(self):
+ finders.find("spam", find_all=True)
+ self.assertEqual(
+ finders.searched_locations,
+ [os.path.join(TEST_ROOT, "project", "documents")],
+ )
+
+ def test_searched_locations_deprecated_all(self):
+ with self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG):
+ finders.find("spam", all=True)
+ self.assertEqual(
+ finders.searched_locations,
+ [os.path.join(TEST_ROOT, "project", "documents")],
+ )
+
+ def test_searched_locations_conflicting_params(self):
+ msg = "find() got multiple values for argument 'find_all'"
+ with (
+ self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ finders.find("spam", find_all=True, all=True)
+
+ def test_searched_locations_unexpected_params(self):
+ msg = "find() got an unexpected keyword argument 'wrong'"
+ with (
+ self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
+ self.assertRaisesMessage(TypeError, msg),
+ ):
+ finders.find("spam", all=True, wrong=1)
+
+ with self.assertRaisesMessage(TypeError, msg):
+ finders.find("spam", find_all=True, wrong=1)
+
+ with self.assertRaisesMessage(TypeError, msg):
+ finders.find("spam", wrong=1)
+
@override_settings(MEDIA_ROOT="")
def test_location_empty(self):
msg = (