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
e5d250bf
Commit
e5d250bf
authored
Apr 01, 2015
by
Awais Jibran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed invalid `usage key` errors which previously throw 500.
TNL-473
parent
10d58d36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
cms/djangoapps/contentstore/views/component.py
+5
-1
cms/djangoapps/contentstore/views/tests/test_container_page.py
+29
-2
No files found.
cms/djangoapps/contentstore/views/component.py
View file @
e5d250bf
...
...
@@ -8,6 +8,7 @@ from django.contrib.auth.decorators import login_required
from
django.views.decorators.http
import
require_GET
from
django.core.exceptions
import
PermissionDenied
from
django.conf
import
settings
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
edxmako.shortcuts
import
render_to_response
...
...
@@ -155,7 +156,10 @@ def container_handler(request, usage_key_string):
"""
if
'text/html'
in
request
.
META
.
get
(
'HTTP_ACCEPT'
,
'text/html'
):
usage_key
=
UsageKey
.
from_string
(
usage_key_string
)
try
:
usage_key
=
UsageKey
.
from_string
(
usage_key_string
)
except
InvalidKeyError
:
# Raise Http404 on invalid 'usage_key_string'
raise
Http404
with
modulestore
()
.
bulk_operations
(
usage_key
.
course_key
):
try
:
course
,
xblock
,
lms_link
,
preview_lms_link
=
_get_item_in_course
(
request
,
usage_key
)
...
...
cms/djangoapps/contentstore/views/tests/test_container_page.py
View file @
e5d250bf
"""
Unit tests for the container page.
"""
import
re
import
datetime
from
pytz
import
UTC
from
mock
import
patch
,
Mock
from
django.http
import
Http404
from
django.test.client
import
RequestFactory
from
django.utils
import
http
import
contentstore.views.component
as
views
from
contentstore.views.tests.utils
import
StudioPageTestCase
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.tests.factories
import
ItemFactory
from
django.utils
import
http
class
ContainerPageTestCase
(
StudioPageTestCase
):
...
...
@@ -158,3 +163,25 @@ class ContainerPageTestCase(StudioPageTestCase):
"""
empty_child_container
=
self
.
_create_item
(
self
.
vertical
.
location
,
'split_test'
,
'Split Test'
)
self
.
validate_preview_html
(
empty_child_container
,
self
.
reorderable_child_view
,
can_add
=
False
)
@patch
(
'contentstore.views.component.render_to_response'
,
Mock
(
return_value
=
Mock
(
status_code
=
200
,
content
=
''
)))
def
test_container_page_with_valid_and_invalid_usage_key_string
(
self
):
"""
Check that invalid 'usage_key_string' raises Http404.
"""
request
=
RequestFactory
()
.
get
(
'foo'
)
request
.
user
=
self
.
user
# Check for invalid 'usage_key_strings'
self
.
assertRaises
(
Http404
,
views
.
container_handler
,
request
,
usage_key_string
=
'i4x://InvalidOrg/InvalidCourse/vertical/static/InvalidContent'
,
)
# Check 200 response if 'usage_key_string' is correct
response
=
views
.
container_handler
(
request
=
request
,
usage_key_string
=
self
.
vertical
.
location
.
to_deprecated_string
()
)
self
.
assertEqual
(
response
.
status_code
,
200
)
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