mirror of
https://github.com/django/django.git
synced 2025-08-19 02:01:29 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
parent
f68fa8b45d
commit
9c19aff7c7
1992 changed files with 139577 additions and 96284 deletions
|
@ -2,7 +2,9 @@ import pathlib
|
|||
|
||||
from django.core.checks import Warning
|
||||
from django.core.checks.caches import (
|
||||
E001, check_cache_location_not_exposed, check_default_cache_is_configured,
|
||||
E001,
|
||||
check_cache_location_not_exposed,
|
||||
check_default_cache_is_configured,
|
||||
check_file_based_cache_is_absolute,
|
||||
)
|
||||
from django.test import SimpleTestCase
|
||||
|
@ -11,13 +13,13 @@ from django.test.utils import override_settings
|
|||
|
||||
class CheckCacheSettingsAppDirsTest(SimpleTestCase):
|
||||
VALID_CACHES_CONFIGURATION = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
},
|
||||
}
|
||||
INVALID_CACHES_CONFIGURATION = {
|
||||
'other': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
"other": {
|
||||
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -45,77 +47,89 @@ class CheckCacheLocationTest(SimpleTestCase):
|
|||
@staticmethod
|
||||
def get_settings(setting, cache_path, setting_path):
|
||||
return {
|
||||
'CACHES': {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||
'LOCATION': cache_path,
|
||||
"CACHES": {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
|
||||
"LOCATION": cache_path,
|
||||
},
|
||||
},
|
||||
setting: [setting_path] if setting == 'STATICFILES_DIRS' else setting_path,
|
||||
setting: [setting_path] if setting == "STATICFILES_DIRS" else setting_path,
|
||||
}
|
||||
|
||||
def test_cache_path_matches_media_static_setting(self):
|
||||
root = pathlib.Path.cwd()
|
||||
for setting in ('MEDIA_ROOT', 'STATIC_ROOT', 'STATICFILES_DIRS'):
|
||||
for setting in ("MEDIA_ROOT", "STATIC_ROOT", "STATICFILES_DIRS"):
|
||||
settings = self.get_settings(setting, root, root)
|
||||
with self.subTest(setting=setting), self.settings(**settings):
|
||||
msg = self.warning_message % ('matches', setting)
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [
|
||||
Warning(msg, id='caches.W002'),
|
||||
])
|
||||
msg = self.warning_message % ("matches", setting)
|
||||
self.assertEqual(
|
||||
check_cache_location_not_exposed(None),
|
||||
[
|
||||
Warning(msg, id="caches.W002"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_cache_path_inside_media_static_setting(self):
|
||||
root = pathlib.Path.cwd()
|
||||
for setting in ('MEDIA_ROOT', 'STATIC_ROOT', 'STATICFILES_DIRS'):
|
||||
settings = self.get_settings(setting, root / 'cache', root)
|
||||
for setting in ("MEDIA_ROOT", "STATIC_ROOT", "STATICFILES_DIRS"):
|
||||
settings = self.get_settings(setting, root / "cache", root)
|
||||
with self.subTest(setting=setting), self.settings(**settings):
|
||||
msg = self.warning_message % ('is inside', setting)
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [
|
||||
Warning(msg, id='caches.W002'),
|
||||
])
|
||||
msg = self.warning_message % ("is inside", setting)
|
||||
self.assertEqual(
|
||||
check_cache_location_not_exposed(None),
|
||||
[
|
||||
Warning(msg, id="caches.W002"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_cache_path_contains_media_static_setting(self):
|
||||
root = pathlib.Path.cwd()
|
||||
for setting in ('MEDIA_ROOT', 'STATIC_ROOT', 'STATICFILES_DIRS'):
|
||||
settings = self.get_settings(setting, root, root / 'other')
|
||||
for setting in ("MEDIA_ROOT", "STATIC_ROOT", "STATICFILES_DIRS"):
|
||||
settings = self.get_settings(setting, root, root / "other")
|
||||
with self.subTest(setting=setting), self.settings(**settings):
|
||||
msg = self.warning_message % ('contains', setting)
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [
|
||||
Warning(msg, id='caches.W002'),
|
||||
])
|
||||
msg = self.warning_message % ("contains", setting)
|
||||
self.assertEqual(
|
||||
check_cache_location_not_exposed(None),
|
||||
[
|
||||
Warning(msg, id="caches.W002"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_cache_path_not_conflict(self):
|
||||
root = pathlib.Path.cwd()
|
||||
for setting in ('MEDIA_ROOT', 'STATIC_ROOT', 'STATICFILES_DIRS'):
|
||||
settings = self.get_settings(setting, root / 'cache', root / 'other')
|
||||
for setting in ("MEDIA_ROOT", "STATIC_ROOT", "STATICFILES_DIRS"):
|
||||
settings = self.get_settings(setting, root / "cache", root / "other")
|
||||
with self.subTest(setting=setting), self.settings(**settings):
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [])
|
||||
|
||||
def test_staticfiles_dirs_prefix(self):
|
||||
root = pathlib.Path.cwd()
|
||||
tests = [
|
||||
(root, root, 'matches'),
|
||||
(root / 'cache', root, 'is inside'),
|
||||
(root, root / 'other', 'contains'),
|
||||
(root, root, "matches"),
|
||||
(root / "cache", root, "is inside"),
|
||||
(root, root / "other", "contains"),
|
||||
]
|
||||
for cache_path, setting_path, msg in tests:
|
||||
settings = self.get_settings(
|
||||
'STATICFILES_DIRS',
|
||||
"STATICFILES_DIRS",
|
||||
cache_path,
|
||||
('prefix', setting_path),
|
||||
("prefix", setting_path),
|
||||
)
|
||||
with self.subTest(path=setting_path), self.settings(**settings):
|
||||
msg = self.warning_message % (msg, 'STATICFILES_DIRS')
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [
|
||||
Warning(msg, id='caches.W002'),
|
||||
])
|
||||
msg = self.warning_message % (msg, "STATICFILES_DIRS")
|
||||
self.assertEqual(
|
||||
check_cache_location_not_exposed(None),
|
||||
[
|
||||
Warning(msg, id="caches.W002"),
|
||||
],
|
||||
)
|
||||
|
||||
def test_staticfiles_dirs_prefix_not_conflict(self):
|
||||
root = pathlib.Path.cwd()
|
||||
settings = self.get_settings(
|
||||
'STATICFILES_DIRS',
|
||||
root / 'cache',
|
||||
('prefix', root / 'other'),
|
||||
"STATICFILES_DIRS",
|
||||
root / "cache",
|
||||
("prefix", root / "other"),
|
||||
)
|
||||
with self.settings(**settings):
|
||||
self.assertEqual(check_cache_location_not_exposed(None), [])
|
||||
|
@ -123,25 +137,32 @@ class CheckCacheLocationTest(SimpleTestCase):
|
|||
|
||||
class CheckCacheAbsolutePath(SimpleTestCase):
|
||||
def test_absolute_path(self):
|
||||
with self.settings(CACHES={
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||
'LOCATION': pathlib.Path.cwd() / 'cache',
|
||||
},
|
||||
}):
|
||||
with self.settings(
|
||||
CACHES={
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
|
||||
"LOCATION": pathlib.Path.cwd() / "cache",
|
||||
},
|
||||
}
|
||||
):
|
||||
self.assertEqual(check_file_based_cache_is_absolute(None), [])
|
||||
|
||||
def test_relative_path(self):
|
||||
with self.settings(CACHES={
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||
'LOCATION': 'cache',
|
||||
},
|
||||
}):
|
||||
self.assertEqual(check_file_based_cache_is_absolute(None), [
|
||||
Warning(
|
||||
"Your 'default' cache LOCATION path is relative. Use an "
|
||||
"absolute path instead.",
|
||||
id='caches.W003',
|
||||
),
|
||||
])
|
||||
with self.settings(
|
||||
CACHES={
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.filebased.FileBasedCache",
|
||||
"LOCATION": "cache",
|
||||
},
|
||||
}
|
||||
):
|
||||
self.assertEqual(
|
||||
check_file_based_cache_is_absolute(None),
|
||||
[
|
||||
Warning(
|
||||
"Your 'default' cache LOCATION path is relative. Use an "
|
||||
"absolute path instead.",
|
||||
id="caches.W003",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue