Debian Codegraph @

tests/check_framework/test_files.py

raw
1 from pathlib import Path
2
3 from django.core.checks import Error
4 from django.core.checks.files import check_setting_file_upload_temp_dir
5 from django.test import SimpleTestCase
6
7
8 class FilesCheckTests(SimpleTestCase):
9 def test_file_upload_temp_dir(self):
10 tests = [
11 None,
12 "",
13 Path.cwd(),
14 str(Path.cwd()),
15 ]
16 for setting in tests:
17 with self.subTest(setting), self.settings(FILE_UPLOAD_TEMP_DIR=setting):
18 self.assertEqual(check_setting_file_upload_temp_dir(None), [])
19
20 def test_file_upload_temp_dir_nonexistent(self):
21 for setting in ["nonexistent", Path("nonexistent")]:
22 with self.subTest(setting), self.settings(FILE_UPLOAD_TEMP_DIR=setting):
23 self.assertEqual(
24 check_setting_file_upload_temp_dir(None),
25 [
26 Error(
27 "The FILE_UPLOAD_TEMP_DIR setting refers to the "
28 "nonexistent directory 'nonexistent'.",
29 id="files.E001",
30 ),
31 ],
32 )