Ticket #15641: 15641.diff
File 15641.diff, 2.7 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/file_storage/tests.py
88 88 89 89 class FileStorageTests(unittest.TestCase): 90 90 storage_class = FileSystemStorage 91 base_url = '/test_media_url/' 91 92 92 93 def setUp(self): 93 94 self.temp_dir = tempfile.mktemp() 94 95 os.makedirs(self.temp_dir) 95 96 self.storage = self.storage_class(location=self.temp_dir, 96 base_url= '/test_media_url/')97 base_url=self.base_url) 97 98 98 99 def tearDown(self): 99 100 shutil.rmtree(self.temp_dir) … … 207 208 # should encode special chars except ~!*()' 208 209 # like encodeURIComponent() JavaScript function do 209 210 self.assertEqual(self.storage.url(r"""~!*()'@#$%^&*abc`+=.file"""), 210 """/test_media_url/~!*()'%40%23%24%25%5E%26*abc%60%2B%3D.file""")211 self.base_url + """~!*()'%40%23%24%25%5E%26*abc%60%2B%3D.file""") 211 212 212 213 # should stanslate os path separator(s) to the url path separator 213 214 self.assertEqual(self.storage.url("""a/b\\c.file"""), 214 """/test_media_url/a/b/c.file""")215 self.base_url + """a/b/c.file""") 215 216 216 217 self.storage.base_url = None 217 218 self.assertRaises(ValueError, self.storage.url, 'test.file') … … 265 266 self.assertRaises(SuspiciousOperation, self.storage.exists, '..') 266 267 self.assertRaises(SuspiciousOperation, self.storage.exists, '/etc/passwd') 267 268 269 class NoUrlFileStorageTests(FileStorageTests): 270 base_url = None 271 272 def test_file_url(self): 273 """ 274 File storage raises ValueError if initialized with base_url=None 275 """ 276 self.assertRaises(ValueError, self.storage.url, 'test.file') 277 278 268 279 class CustomStorage(FileSystemStorage): 269 280 def get_available_name(self, name): 270 281 """ -
django/core/files/storage.py
142 142 """ 143 143 raise NotImplementedError() 144 144 145 UNUSABLE_BASE_URL = object() 146 145 147 class FileSystemStorage(Storage): 146 148 """ 147 149 Standard filesystem storage 148 150 """ 149 151 150 def __init__(self, location=None, base_url= None):152 def __init__(self, location=None, base_url=UNUSABLE_BASE_URL): 151 153 if location is None: 152 154 location = settings.MEDIA_ROOT 153 if base_url is None:155 if base_url is UNUSABLE_BASE_URL: 154 156 base_url = settings.MEDIA_URL 155 157 self.location = os.path.abspath(location) 156 158 self.base_url = base_url