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
37ec01dd
Commit
37ec01dd
authored
May 16, 2013
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle ItemNotFoundError from the modulestore to avoid 500 errors
parent
6dcf7be0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
7 deletions
+42
-7
lms/djangoapps/courseware/module_render.py
+17
-1
lms/djangoapps/courseware/tests/test_module_render.py
+25
-6
No files found.
lms/djangoapps/courseware/module_render.py
View file @
37ec01dd
...
...
@@ -402,6 +402,11 @@ def modx_dispatch(request, dispatch, location, course_id):
through the part before the first '?'.
- location -- the module location. Used to look up the XModule instance
- course_id -- defines the course context for this request.
Raises PermissionDenied if the user is not logged in. Raises Http404 if
the location and course_id do not identify a valid module, the module is
not accessible by the user, or the module raises NotFoundError. If the
module raises any other error, it will escape this function.
'''
# ''' (fix emacs broken parsing)
...
...
@@ -430,8 +435,19 @@ def modx_dispatch(request, dispatch, location, course_id):
return
HttpResponse
(
json
.
dumps
({
'success'
:
file_too_big_msg
}))
p
[
fileinput_id
]
=
inputfiles
try
:
descriptor
=
modulestore
()
.
get_instance
(
course_id
,
location
)
except
ItemNotFoundError
:
log
.
warn
(
"Invalid location for course id {course_id}: {location}"
.
format
(
course_id
=
course_id
,
location
=
location
)
)
raise
Http404
model_data_cache
=
ModelDataCache
.
cache_for_descriptor_descendents
(
course_id
,
request
.
user
,
modulestore
()
.
get_instance
(
course_id
,
location
)
)
request
.
user
,
descriptor
)
instance
=
get_module
(
request
.
user
,
request
,
location
,
model_data_cache
,
course_id
,
grade_bucket_type
=
'ajax'
)
if
instance
is
None
:
...
...
lms/djangoapps/courseware/tests/test_module_render.py
View file @
37ec01dd
...
...
@@ -69,19 +69,38 @@ class ModuleRenderTestCase(LoginEnrollmentTestCase):
json
.
dumps
({
'success'
:
'Submission aborted! Your file "
%
s" is too large (max size:
%
d MB)'
%
(
inputfile
.
name
,
settings
.
STUDENT_FILEUPLOAD_MAX_SIZE
/
(
1000
**
2
))}))
mock_request_3
=
MagicMock
()
mock_request_3
.
POST
.
copy
.
return_value
=
{}
mock_request_3
.
POST
.
copy
.
return_value
=
{
'position'
:
1
}
mock_request_3
.
FILES
=
False
mock_request_3
.
user
=
UserFactory
()
inputfile_2
=
Stub
()
inputfile_2
.
size
=
1
inputfile_2
.
name
=
'name'
self
.
assertRaises
(
ItemNotFoundError
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
location
,
'toy'
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'dummy'
,
self
.
location
,
self
.
course_id
)
mock_request_3
.
POST
.
copy
.
return_value
=
{
'position'
:
1
}
self
.
assertIsInstance
(
render
.
modx_dispatch
(
mock_request_3
,
'goto_position'
,
self
.
location
,
self
.
course_id
),
HttpResponse
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'goto_position'
,
self
.
location
,
'bad_course_id'
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'goto_position'
,
[
'i4x'
,
'edX'
,
'toy'
,
'chapter'
,
'bad_location'
],
self
.
course_id
)
self
.
assertRaises
(
Http404
,
render
.
modx_dispatch
,
mock_request_3
,
'bad_dispatch'
,
self
.
location
,
self
.
course_id
)
def
test_get_score_bucket
(
self
):
self
.
assertEquals
(
render
.
get_score_bucket
(
0
,
10
),
'incorrect'
)
...
...
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