Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a37166c3
Commit
a37166c3
authored
Mar 31, 2015
by
jsa
Committed by
Andy Armstrong
Apr 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove catchall exception handling in profile image api
parent
bb2599ce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
54 deletions
+27
-54
openedx/core/djangoapps/profile_images/tests/test_views.py
+4
-12
openedx/core/djangoapps/profile_images/views.py
+23
-42
No files found.
openedx/core/djangoapps/profile_images/tests/test_views.py
View file @
a37166c3
...
@@ -223,12 +223,8 @@ class ProfileImageUploadTestCase(ProfileImageEndpointTestCase):
...
@@ -223,12 +223,8 @@ class ProfileImageUploadTestCase(ProfileImageEndpointTestCase):
"""
"""
image_open
.
side_effect
=
[
Exception
(
u"whoops"
),
None
]
image_open
.
side_effect
=
[
Exception
(
u"whoops"
),
None
]
with
make_image_file
()
as
image_file
:
with
make_image_file
()
as
image_file
:
response
=
self
.
client
.
post
(
self
.
url
,
{
'file'
:
image_file
},
format
=
'multipart'
)
with
self
.
assertRaises
(
Exception
):
self
.
check_response
(
self
.
client
.
post
(
self
.
url
,
{
'file'
:
image_file
},
format
=
'multipart'
)
response
,
400
,
expected_developer_message
=
u"Upload failed for profile image: whoops"
,
expected_user_message
=
u"Upload failed for profile image"
,
)
self
.
check_images
(
False
)
self
.
check_images
(
False
)
self
.
check_has_profile_image
(
False
)
self
.
check_has_profile_image
(
False
)
self
.
assertFalse
(
mock_log
.
info
.
called
)
self
.
assertFalse
(
mock_log
.
info
.
called
)
...
@@ -321,12 +317,8 @@ class ProfileImageRemoveTestCase(ProfileImageEndpointTestCase):
...
@@ -321,12 +317,8 @@ class ProfileImageRemoveTestCase(ProfileImageEndpointTestCase):
messages are returned.
messages are returned.
"""
"""
user_profile_save
.
side_effect
=
[
Exception
(
u"whoops"
),
None
]
user_profile_save
.
side_effect
=
[
Exception
(
u"whoops"
),
None
]
response
=
self
.
client
.
post
(
self
.
url
)
with
self
.
assertRaises
(
Exception
):
self
.
check_response
(
self
.
client
.
post
(
self
.
url
)
response
,
400
,
expected_developer_message
=
u"Delete failed for profile image: whoops"
,
expected_user_message
=
u"Delete failed for profile image"
,
)
self
.
check_images
(
True
)
# thumbnails should remain intact.
self
.
check_images
(
True
)
# thumbnails should remain intact.
self
.
check_has_profile_image
(
True
)
self
.
check_has_profile_image
(
True
)
self
.
assertFalse
(
mock_log
.
info
.
called
)
self
.
assertFalse
(
mock_log
.
info
.
called
)
openedx/core/djangoapps/profile_images/views.py
View file @
a37166c3
...
@@ -80,41 +80,31 @@ class ProfileImageUploadView(APIView):
...
@@ -80,41 +80,31 @@ class ProfileImageUploadView(APIView):
status
=
status
.
HTTP_400_BAD_REQUEST
status
=
status
.
HTTP_400_BAD_REQUEST
)
)
try
:
# process the upload.
# process the upload.
uploaded_file
=
request
.
FILES
[
'file'
]
uploaded_file
=
request
.
FILES
[
'file'
]
# no matter what happens, delete the temporary file when we're done
# no matter what happens, delete the temporary file when we're done
with
closing
(
uploaded_file
):
with
closing
(
uploaded_file
):
# image file validation.
# image file validation.
try
:
try
:
validate_uploaded_image
(
uploaded_file
)
validate_uploaded_image
(
uploaded_file
)
except
ImageValidationError
as
error
:
except
ImageValidationError
as
error
:
return
Response
(
return
Response
(
{
"developer_message"
:
error
.
message
,
"user_message"
:
error
.
user_message
},
{
"developer_message"
:
error
.
message
,
"user_message"
:
error
.
user_message
},
status
=
status
.
HTTP_400_BAD_REQUEST
,
status
=
status
.
HTTP_400_BAD_REQUEST
,
)
# generate profile pic and thumbnails and store them
profile_image_names
=
get_profile_image_names
(
username
)
create_profile_images
(
uploaded_file
,
profile_image_names
)
# update the user account to reflect that a profile image is available.
set_has_profile_image
(
username
,
True
,
_make_upload_dt
())
log
.
info
(
LOG_MESSAGE_CREATE
,
{
'image_names'
:
profile_image_names
.
values
(),
'user_id'
:
request
.
user
.
id
}
)
)
except
Exception
as
error
:
return
Response
(
{
"developer_message"
:
u"Upload failed for profile image: {error}"
.
format
(
error
=
error
),
"user_message"
:
_
(
u"Upload failed for profile image"
),
},
# generate profile pic and thumbnails and store them
status
=
status
.
HTTP_400_BAD_REQUEST
profile_image_names
=
get_profile_image_names
(
username
)
create_profile_images
(
uploaded_file
,
profile_image_names
)
# update the user account to reflect that a profile image is available.
set_has_profile_image
(
username
,
True
,
_make_upload_dt
())
log
.
info
(
LOG_MESSAGE_CREATE
,
{
'image_names'
:
profile_image_names
.
values
(),
'user_id'
:
request
.
user
.
id
}
)
)
# send client response.
# send client response.
...
@@ -165,15 +155,6 @@ class ProfileImageRemoveView(APIView):
...
@@ -165,15 +155,6 @@ class ProfileImageRemoveView(APIView):
)
)
except
UserNotFound
:
except
UserNotFound
:
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
except
Exception
as
error
:
return
Response
(
{
"developer_message"
:
u"Delete failed for profile image: {error}"
.
format
(
error
=
error
),
"user_message"
:
_
(
u"Delete failed for profile image"
),
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
# send client response.
# send client response.
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
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