Catch InvalidKeyError in static_tab view.
LMS-11189
This commit is contained in:
@@ -49,9 +49,11 @@ def get_request_for_user(user):
|
||||
|
||||
request = RequestFactory()
|
||||
request.user = user
|
||||
request.COOKIES = {}
|
||||
request.META = {}
|
||||
request.is_secure = lambda: True
|
||||
request.get_host = lambda: "edx.org"
|
||||
request.method = 'GET'
|
||||
return request
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ Test cases for tabs.
|
||||
from mock import MagicMock, Mock, patch
|
||||
|
||||
from courseware.courses import get_course_by_id
|
||||
from courseware.views import get_static_tab_contents
|
||||
from courseware.views import get_static_tab_contents, static_tab
|
||||
|
||||
from django.http import Http404
|
||||
from django.test.utils import override_settings
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
@@ -43,6 +44,11 @@ class StaticTabDateTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertIn("OOGIE BLOOGIE", resp.content)
|
||||
|
||||
def test_invalid_course_key(self):
|
||||
request = get_request_for_user(UserFactory.create())
|
||||
with self.assertRaises(Http404):
|
||||
static_tab(request, 'edX/toy', 'new_tab')
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
|
||||
def test_get_static_tab_contents(self):
|
||||
course = get_course_by_id(self.toy_course_key)
|
||||
|
||||
@@ -549,7 +549,11 @@ def static_tab(request, course_id, tab_slug):
|
||||
|
||||
Assumes the course_id is in a valid format.
|
||||
"""
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
try:
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
except InvalidKeyError:
|
||||
raise Http404
|
||||
|
||||
course = get_course_with_access(request.user, 'load', course_key)
|
||||
|
||||
tab = CourseTabList.get_tab_by_slug(course.tabs, tab_slug)
|
||||
|
||||
Reference in New Issue
Block a user