diff options
| author | Yuval Adam <yuval@segmanta.com> | 2014-03-20 17:49:16 +0200 |
|---|---|---|
| committer | Yuval Adam <yuval@segmanta.com> | 2014-03-20 17:49:16 +0200 |
| commit | 75f93a3f7854a7383febd047391e2bfd4caceee0 (patch) | |
| tree | d5e634ef292c6b84acacc3982dbcaa0d300a346e /storages/tests/hashpath.py | |
Diffstat (limited to 'storages/tests/hashpath.py')
| -rw-r--r-- | storages/tests/hashpath.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/storages/tests/hashpath.py b/storages/tests/hashpath.py new file mode 100644 index 0000000..5cc4d65 --- /dev/null +++ b/storages/tests/hashpath.py @@ -0,0 +1,35 @@ +import os +import shutil + +from django.test import TestCase +from django.core.files.base import ContentFile +from django.conf import settings + +from storages.backends.hashpath import HashPathStorage + +TEST_PATH_PREFIX = 'django-storages-test' + + +class HashPathStorageTest(TestCase): + + def setUp(self): + self.test_path = os.path.join(settings.MEDIA_ROOT, TEST_PATH_PREFIX) + self.storage = HashPathStorage(location=self.test_path) + + # make sure the profile upload folder exists + if not os.path.exists(self.test_path): + os.makedirs(self.test_path) + + def tearDown(self): + # remove uploaded profile picture + if os.path.exists(self.test_path): + shutil.rmtree(self.test_path) + + def test_save_same_file(self): + """ + saves a file twice, the file should only be stored once, because the + content/hash is the same + """ + path_1 = self.storage.save('test', ContentFile('new content')) + path_2 = self.storage.save('test', ContentFile('new content')) + self.assertEqual(path_1, path_2) |
