2021-01-20 16:12:24 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from django.core.checks import Error
|
|
|
|
from django.core.checks.files import check_setting_file_upload_temp_dir
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class FilesCheckTests(SimpleTestCase):
|
|
|
|
def test_file_upload_temp_dir(self):
|
|
|
|
tests = [
|
|
|
|
None,
|
2022-02-03 19:24:19 +00:00
|
|
|
"",
|
2021-01-20 16:12:24 +00:00
|
|
|
Path.cwd(),
|
|
|
|
str(Path.cwd()),
|
|
|
|
]
|
|
|
|
for setting in tests:
|
|
|
|
with self.subTest(setting), self.settings(FILE_UPLOAD_TEMP_DIR=setting):
|
|
|
|
self.assertEqual(check_setting_file_upload_temp_dir(None), [])
|
|
|
|
|
|
|
|
def test_file_upload_temp_dir_nonexistent(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
for setting in ["nonexistent", Path("nonexistent")]:
|
2021-01-20 16:12:24 +00:00
|
|
|
with self.subTest(setting), self.settings(FILE_UPLOAD_TEMP_DIR=setting):
|
|
|
|
self.assertEqual(
|
|
|
|
check_setting_file_upload_temp_dir(None),
|
|
|
|
[
|
|
|
|
Error(
|
|
|
|
"The FILE_UPLOAD_TEMP_DIR setting refers to the "
|
|
|
|
"nonexistent directory 'nonexistent'.",
|
2022-02-03 19:24:19 +00:00
|
|
|
id="files.E001",
|
2021-01-20 16:12:24 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|