Commit baaf5fa8 by zubair-arbi

Merge pull request #6210 from edx/zub/bugfix/tnl-922-key-error-getting-position

set position to default value if POST request don't have position argume...
parents 8a685cec 1d6d2f2a
......@@ -88,7 +88,13 @@ class SequenceModule(SequenceFields, XModule):
def handle_ajax(self, dispatch, data): # TODO: bounds checking
''' get = request.POST instance '''
if dispatch == 'goto_position':
self.position = int(data['position'])
# set position to default value if either 'position' argument not
# found in request or it is a non-positive integer
position = data.get('position', u'1')
if position.isdigit() and int(position) > 0:
self.position = int(position)
else:
self.position = 1
return json.dumps({'success': True})
raise NotFoundError('Unexpected dispatch type')
......
# -*- coding: utf-8 -*-
"""
Test for lms courseware app, module render unit
"""
......@@ -177,6 +178,44 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertEquals(403, response.status_code)
self.assertEquals('Unauthenticated', response.content)
def test_missing_position_handler(self):
"""
Test that sending POST request without or invalid position argument don't raise server error
"""
self.client.login(username=self.mock_user.username, password="test")
dispatch_url = reverse(
'xblock_handler',
args=[
self.course_key.to_deprecated_string(),
quote_slashes(self.course_key.make_usage_key('videosequence', 'Toy_Videos').to_deprecated_string()),
'xmodule_handler',
'goto_position'
]
)
response = self.client.post(dispatch_url)
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
response = self.client.post(dispatch_url, {'position': ''})
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
response = self.client.post(dispatch_url, {'position': '-1'})
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
response = self.client.post(dispatch_url, {'position': "string"})
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
response = self.client.post(dispatch_url, {'position': u"Φυσικά"})
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
response = self.client.post(dispatch_url, {'position': None})
self.assertEqual(200, response.status_code)
self.assertEqual(json.loads(response.content), {'success': True})
@ddt.data('pure', 'vertical')
@XBlock.register_temp_plugin(PureXBlock, identifier='pure')
def test_rebinding_same_user(self, block_type):
......
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