2012-09-10 03:07:04 +08:00
|
|
|
import os
|
2013-07-01 20:22:27 +08:00
|
|
|
import unittest
|
2012-09-10 03:07:04 +08:00
|
|
|
|
2012-09-08 04:49:22 +08:00
|
|
|
from django.utils._os import safe_join
|
|
|
|
|
|
|
|
|
|
|
|
class SafeJoinTests(unittest.TestCase):
|
|
|
|
def test_base_path_ends_with_sep(self):
|
2012-09-10 03:07:04 +08:00
|
|
|
drive, path = os.path.splitdrive(safe_join("/abc/", "abc"))
|
2012-09-08 04:49:22 +08:00
|
|
|
self.assertEqual(
|
2012-09-10 03:07:04 +08:00
|
|
|
path,
|
|
|
|
"{0}abc{0}abc".format(os.path.sep)
|
2012-09-08 04:49:22 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_root_path(self):
|
2012-09-10 03:07:04 +08:00
|
|
|
drive, path = os.path.splitdrive(safe_join("/", "path"))
|
2012-09-08 04:49:22 +08:00
|
|
|
self.assertEqual(
|
2012-09-10 03:07:04 +08:00
|
|
|
path,
|
|
|
|
"{0}path".format(os.path.sep),
|
2012-09-08 04:49:22 +08:00
|
|
|
)
|
|
|
|
|
2012-09-10 03:07:04 +08:00
|
|
|
drive, path = os.path.splitdrive(safe_join("/", ""))
|
2012-09-08 04:49:22 +08:00
|
|
|
self.assertEqual(
|
2012-09-10 03:07:04 +08:00
|
|
|
path,
|
|
|
|
os.path.sep,
|
2012-09-08 04:49:22 +08:00
|
|
|
)
|