Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
60265a1a
Commit
60265a1a
authored
Feb 06, 2018
by
Diederik van der Boor
Browse files
Fix test for Django 1.8/1.9
parent
a81d26d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
private_storage/fields.py
View file @
60265a1a
...
...
@@ -6,6 +6,7 @@ import logging
import
os
import
posixpath
import
django
from
django.core.exceptions
import
ValidationError
from
django.core.files.uploadedfile
import
UploadedFile
from
django.db
import
models
...
...
@@ -65,7 +66,7 @@ class PrivateFileField(models.FileField):
path_parts
=
[]
if
self
.
upload_to
:
# Support the upload_to callable that Django
1.9+
provides
# Support the upload_to callable that Django provides
if
callable
(
self
.
upload_to
):
dirname
,
filename
=
os
.
path
.
split
(
self
.
upload_to
(
instance
,
filename
))
path_parts
.
append
(
dirname
)
...
...
@@ -88,8 +89,11 @@ class PrivateFileField(models.FileField):
path_parts
=
[
self
.
get_directory_name
()]
path_parts
.
append
(
self
.
_get_clean_filename
(
filename
))
filename
=
posixpath
.
join
(
*
path_parts
)
return
self
.
storage
.
generate_filename
(
filename
)
if
django
.
VERSION
>=
(
1
,
10
):
filename
=
posixpath
.
join
(
*
path_parts
)
return
self
.
storage
.
generate_filename
(
filename
)
else
:
return
os
.
path
.
join
(
*
path_parts
)
def
_get_clean_filename
(
self
,
filename
):
# As of Django 1.10+, file names are no longer cleaned locally, but cleaned by the storage.
...
...
private_storage/tests/utils.py
View file @
60265a1a
...
...
@@ -12,7 +12,8 @@ class PrivateFileTestCase(TestCase):
Empty the test folder after each test case.
"""
super
(
PrivateFileTestCase
,
self
).
tearDown
()
shutil
.
rmtree
(
settings
.
PRIVATE_STORAGE_ROOT
)
if
os
.
path
.
exists
(
settings
.
PRIVATE_STORAGE_ROOT
):
shutil
.
rmtree
(
settings
.
PRIVATE_STORAGE_ROOT
)
def
assertExists
(
self
,
*
parts
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment