44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from django.test import TestCase
|
|
from byostorage.multi import MultiStorage
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
import os.path
|
|
|
|
class MultiStorageTestCase(TestCase):
|
|
|
|
def test_storage_selection(self):
|
|
ms = MultiStorage({'one': {'location': 'storage/one'}, 'two': {}})
|
|
self.assertEqual(str(ms), "<MultiStorage: 2 storages>")
|
|
|
|
# use the default if nothing set
|
|
default = ms.get_storage('foo')
|
|
self.assertIsInstance(default, FileSystemStorage)
|
|
self.assertEqual(default.base_location, 'media')
|
|
|
|
# get first instance
|
|
one = ms.get_storage('one')
|
|
self.assertEqual(one.base_location, 'storage/one')
|
|
|
|
def test_storage_proxies(self):
|
|
ms = MultiStorage({
|
|
'one': {'location': 'storage/one', 'base_url': 'http://one'},
|
|
'two': {'location': 'storage/two', 'base_url': 'http://two'}
|
|
})
|
|
|
|
|
|
self.assertEqual(ms.url("one:foo.txt"), 'http://one/foo.txt')
|
|
self.assertEqual(ms.url("two:foo.txt"), 'http://two/foo.txt')
|
|
|
|
def test_with_http(self):
|
|
ms = MultiStorage({
|
|
'https': {'storage': 'byostorage.http.HTTPStorage', 'protocol': 'https'}
|
|
})
|
|
|
|
self.assertEqual(ms.url('https://google.com'), 'https://google.com')
|
|
|
|
def test_local_methods(self):
|
|
ms = MultiStorage({
|
|
'local': {'storage': 'django.core.files.storage.FileSystemStorage', 'location': 'local_store'}
|
|
})
|
|
|
|
self.assertEqual(ms.path('local:foo/bar.txt'), os.path.realpath('local_store/foo/bar.txt')) |