test_os_utils.py 844 B

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import unittest
  3. from django.core.exceptions import SuspiciousFileOperation
  4. from django.utils._os import safe_join
  5. class SafeJoinTests(unittest.TestCase):
  6. def test_base_path_ends_with_sep(self):
  7. drive, path = os.path.splitdrive(safe_join("/abc/", "abc"))
  8. self.assertEqual(
  9. path,
  10. "{0}abc{0}abc".format(os.path.sep)
  11. )
  12. def test_root_path(self):
  13. drive, path = os.path.splitdrive(safe_join("/", "path"))
  14. self.assertEqual(
  15. path,
  16. "{}path".format(os.path.sep),
  17. )
  18. drive, path = os.path.splitdrive(safe_join("/", ""))
  19. self.assertEqual(
  20. path,
  21. os.path.sep,
  22. )
  23. def test_parent_path(self):
  24. with self.assertRaises(SuspiciousFileOperation):
  25. safe_join("/abc/", "../def")