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
2b6fc26c
Unverified
Commit
2b6fc26c
authored
May 23, 2018
by
Diederik van der Boor
Browse files
Fix PrivateFile.exists() check when no file is given
parent
f140b819
Changes
2
Hide whitespace changes
Inline
Side-by-side
private_storage/models.py
View file @
2b6fc26c
...
@@ -35,7 +35,7 @@ class PrivateFile(object):
...
@@ -35,7 +35,7 @@ class PrivateFile(object):
"""
"""
Check whether the file exists.
Check whether the file exists.
"""
"""
return
self
.
storage
.
exists
(
self
.
relative_name
)
return
self
.
relative_name
and
self
.
storage
.
exists
(
self
.
relative_name
)
@
cached_property
@
cached_property
def
content_type
(
self
):
def
content_type
(
self
):
...
...
private_storage/tests/test_models.py
View file @
2b6fc26c
from
django.test
import
RequestFactory
,
SimpleTestCase
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
private_storage.models
import
PrivateFile
from
private_storage.storage
import
private_storage
from
private_storage.tests.models
import
CustomerDossier
,
CustomerDossierJoin
,
SimpleDossier
,
\
from
private_storage.tests.models
import
CustomerDossier
,
CustomerDossierJoin
,
SimpleDossier
,
\
UploadToCallableDossier
,
UploadToDossier
UploadToCallableDossier
,
UploadToDossier
from
private_storage.tests.utils
import
PrivateFileTestCase
from
private_storage.tests.utils
import
PrivateFileTestCase
...
@@ -26,3 +29,10 @@ class ModelTests(PrivateFileTestCase):
...
@@ -26,3 +29,10 @@ class ModelTests(PrivateFileTestCase):
def
test_upload_subfolder_join
(
self
):
def
test_upload_subfolder_join
(
self
):
obj
=
CustomerDossierJoin
.
objects
.
create
(
customer
=
'cust4'
,
file
=
SimpleUploadedFile
(
'test6.txt'
,
b
'test6'
))
obj
=
CustomerDossierJoin
.
objects
.
create
(
customer
=
'cust4'
,
file
=
SimpleUploadedFile
(
'test6.txt'
,
b
'test6'
))
self
.
assertExists
(
'CustomerDossierJoin'
,
'cust4'
,
'sub2'
,
'test6.txt'
)
self
.
assertExists
(
'CustomerDossierJoin'
,
'cust4'
,
'sub2'
,
'test6.txt'
)
class
PrivateFileTests
(
SimpleTestCase
):
def
test_privatefile_exists_none
(
self
):
# Retrieving a FieldFile(none) should not give errors
request
=
RequestFactory
().
get
(
'/'
)
self
.
assertFalse
(
PrivateFile
(
request
,
private_storage
,
None
).
exists
())
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