This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched django local storage to overwrite
The default django local storage does not allow to overwrite files with the same name and this is a problem for our static assets.
- Loading branch information
Giovanni Di Milia
committed
Sep 18, 2015
1 parent
f3b224d
commit 1b31e5a
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Tests for django storage | ||
""" | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
from shutil import rmtree | ||
from tempfile import mkdtemp | ||
|
||
from django.conf import settings | ||
from django.core.files.base import ContentFile | ||
from django.core.files.storage import default_storage | ||
from django.test.testcases import TestCase | ||
|
||
|
||
class TestStorage(TestCase): | ||
""" | ||
Tests for Django storage | ||
""" | ||
|
||
def test_local_storage(self): | ||
""" | ||
Tests for local storage | ||
It has to be OverwriteStorage to avoid problems with static assets | ||
having the same name | ||
""" | ||
|
||
# default setting | ||
self.assertEqual( | ||
settings.DEFAULT_FILE_STORAGE, | ||
'storages.backends.overwrite.OverwriteStorage' | ||
) | ||
|
||
temp_dir_path = mkdtemp() | ||
self.addCleanup(rmtree, temp_dir_path) | ||
|
||
path = os.path.join(temp_dir_path, 'temp_file.txt') | ||
|
||
# create the first file | ||
default_storage.save(path, ContentFile('nonsense content')) | ||
# create another with the same name | ||
content = 'nonsense content 2' | ||
default_storage.save(path, ContentFile(content)) | ||
|
||
# there is only one file in the directory | ||
self.assertEqual(len(os.listdir(temp_dir_path)), 1) | ||
|
||
with open(path) as fhand: | ||
content_read = fhand.read() | ||
self.assertEqual(content, content_read) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters