Skip to content

Commit

Permalink
Merge pull request #2 from tundebabzy/issue_1
Browse files Browse the repository at this point in the history
Issue 1
  • Loading branch information
klis87 authored Jan 13, 2017
2 parents 711af26 + 0a0a072 commit 51d2179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cloudinary_storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _upload(self, name, content):
return cloudinary.uploader.upload(content, **options)

def _save(self, name, content):
name = self._normalise_name(name)
name = self._prepend_prefix(name)
content = UploadedFile(content, name)
response = self._upload(name, content)
Expand Down Expand Up @@ -117,6 +118,9 @@ def listdir(self, path):
files.append(resource_tail)
return list(directories), files

def _normalise_name(self, name):
return name.replace('\\', '/')


class RawMediaCloudinaryStorage(MediaCloudinaryStorage):
RESOURCE_TYPE = RESOURCE_TYPES['RAW']
Expand Down
14 changes: 11 additions & 3 deletions tests/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.conf import settings

from cloudinary_storage.storage import (MediaCloudinaryStorage, ManifestCloudinaryStorage, StaticCloudinaryStorage,
StaticHashedCloudinaryStorage)
StaticHashedCloudinaryStorage)
from cloudinary_storage import app_settings
from tests.tests.test_helpers import get_random_name, import_mock

Expand All @@ -25,8 +25,8 @@ def setUpClass(cls):
cls.file_name, cls.file = cls.upload_file()

@classmethod
def upload_file(cls, prefix=''):
file_name = prefix + get_random_name()
def upload_file(cls, prefix='', directory_name=''):
file_name = prefix + directory_name + get_random_name()
content = ContentFile(cls.file_content)
file_name = cls.storage.save(file_name, content)
return file_name, content
Expand Down Expand Up @@ -106,6 +106,14 @@ def test_list_dir(self):
finally:
self.storage.delete(file_2_name)

def test_file_with_windows_path_uploaded_and_exists(self):
file_name, file = self.upload_file(directory_name='windows\\styled\\path\\')
try:
self.assertTrue(self.storage.exists(file_name))
finally:
self.storage.delete(file_name)


@classmethod
def tearDownClass(cls):
super(CloudinaryMediaStorageTests, cls).tearDownClass()
Expand Down

0 comments on commit 51d2179

Please sign in to comment.