This repository was archived by the owner on Sep 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_storage_backends.py
More file actions
48 lines (33 loc) · 1.55 KB
/
test_storage_backends.py
File metadata and controls
48 lines (33 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
import os
import shutil
import unittest
from tests.utils import has_installed
from thumbnails.storage_backends import (BaseStorageBackend, DjangoStorageBackend,
FilesystemStorageBackend)
class StorageBackendTestMixin(object):
def setUp(self):
self.backend = self.BACKEND()
def test_exists(self):
self.assertTrue(self.backend.exists(os.path.join(os.getcwd(), 'setup.py')))
self.assertFalse(self.backend.exists(os.path.join(os.getcwd(), 'stup.py')))
def test_save(self):
self.backend.save('t/est_file', b'123')
self.assertTrue(os.path.exists(self.backend.path('t/est_file')))
shutil.rmtree(self.backend.path('t'))
class BaseStorageBackendTestCase(unittest.TestCase):
def setUp(self):
self.backend = BaseStorageBackend()
def test_path(self):
self.assertEqual(self.backend.path('/an/absolute/path'), '/an/absolute/path')
self.backend.location = 'location'
self.assertEqual(self.backend.path('relative/path'), 'location/relative/path')
class FilesystemStorageBackendTestCase(StorageBackendTestMixin, unittest.TestCase):
BACKEND = FilesystemStorageBackend
def test_create_location_in_init(self):
shutil.rmtree(self.backend.location)
instance = self.BACKEND()
os.path.exists(instance.location)
@unittest.skipIf(not has_installed('django'), 'Django not installed')
class DjangoStorageBackendTestCase(StorageBackendTestMixin, unittest.TestCase):
BACKEND = DjangoStorageBackend