test_files.py 1.1 KB

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