Commit 06dbb68e by Mat Peterson

courseware/views.py index function position value integer error correction and test

LMS-2844
parent 68087903
...@@ -80,13 +80,13 @@ class ViewsTestCase(TestCase): ...@@ -80,13 +80,13 @@ class ViewsTestCase(TestCase):
Tests for views.py methods. Tests for views.py methods.
""" """
def setUp(self): def setUp(self):
course = CourseFactory() self.course = CourseFactory()
chapter = ItemFactory(category='chapter', parent_location=course.location) # pylint: disable=no-member self.chapter = ItemFactory(category='chapter', parent_location=self.course.location) # pylint: disable=no-member
section = ItemFactory(category='sequential', parent_location=chapter.location, due=datetime(2013, 9, 18, 11, 30, 00)) self.section = ItemFactory(category='sequential', parent_location=self.chapter.location, due=datetime(2013, 9, 18, 11, 30, 00))
vertical = ItemFactory(category='vertical', parent_location=section.location) self.vertical = ItemFactory(category='vertical', parent_location=self.section.location)
self.component = ItemFactory(category='problem', parent_location=vertical.location) self.component = ItemFactory(category='problem', parent_location=self.vertical.location)
self.course_key = course.id self.course_key = self.course.id
self.user = User.objects.create(username='dummy', password='123456', self.user = User.objects.create(username='dummy', password='123456',
email='test@mit.edu') email='test@mit.edu')
self.date = datetime(2013, 1, 22, tzinfo=UTC) self.date = datetime(2013, 1, 22, tzinfo=UTC)
...@@ -147,6 +147,17 @@ class ViewsTestCase(TestCase): ...@@ -147,6 +147,17 @@ class ViewsTestCase(TestCase):
self.assertRaises(Http404, views.redirect_to_course_position, self.assertRaises(Http404, views.redirect_to_course_position,
mock_module, views.CONTENT_DEPTH) mock_module, views.CONTENT_DEPTH)
def test_index_invalid_position(self):
request_url = '/'.join([
'/courses',
self.course.id.to_deprecated_string(),
self.chapter.location.name,
self.section.location.name,
'f'
])
response = self.client.get(request_url)
self.assertEqual(response.status_code, 404)
def test_registered_for_course(self): def test_registered_for_course(self):
self.assertFalse(views.registered_for_course('Basketweaving', None)) self.assertFalse(views.registered_for_course('Basketweaving', None))
mock_user = MagicMock() mock_user = MagicMock()
......
...@@ -354,6 +354,13 @@ def index(request, course_id, chapter=None, section=None, ...@@ -354,6 +354,13 @@ def index(request, course_id, chapter=None, section=None,
section_field_data_cache = FieldDataCache.cache_for_descriptor_descendents( section_field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
course_key, user, section_descriptor, depth=None) course_key, user, section_descriptor, depth=None)
# Verify that position a string is in fact an int
if position is not None:
try:
int(position)
except ValueError:
raise Http404("Position {} is not an integer!".format(position))
section_module = get_module_for_descriptor( section_module = get_module_for_descriptor(
request.user, request.user,
request, request,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment