1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #22712 -- Avoided name shadowing of "all" in django.contrib.staticfiles.finders.

Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
This commit is contained in:
Andreu Vallbona
2024-06-08 20:36:58 +02:00
committed by nessita
parent dfac15d570
commit 0fdcf1029c
5 changed files with 155 additions and 17 deletions

View File

@@ -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 = (