Commit 576be233 by Muhammad Shoaib

added the check to validate the non-integer input only when the allowance type…

added the check to validate the non-integer input only when the allowance type is addition time granted
parent f5ae9bac
......@@ -144,7 +144,7 @@ class SoftwareSecureTests(TestCase):
self.assertEqual(attempt['external_id'], 'foobar')
self.assertIsNone(attempt['started_at'])
@ddt.data(None, '10')
@ddt.data(None, 'additional person allowed in room')
def test_attempt_with_review_policy(self, review_policy_exception):
"""
Create an unstarted proctoring attempt with a review policy associated with it.
......
......@@ -712,12 +712,11 @@ class ProctoredExamStudentAllowance(TimeStampedModel):
if isinstance(key, tuple) and len(key) > 0:
key = key[0]
if not value.isdigit():
if not cls.is_allowance_value_valid(key, value):
err_msg = (
'allowance_value "{value}" should be non-negative integer value.'
).format(value=value)
raise AllowanceValueNotAllowedException(err_msg)
# were we passed a PK?
if isinstance(user_info, (int, long)):
user_id = user_info
......@@ -747,6 +746,18 @@ class ProctoredExamStudentAllowance(TimeStampedModel):
cls.objects.create(proctored_exam_id=exam_id, user_id=user_id, key=key, value=value)
@classmethod
def is_allowance_value_valid(cls, allowance_type, allowance_value):
"""
Method that validates the allowance value against the allowance type
"""
# validates the allowance value only when the allowance type is "ADDITIONAL_TIME_GRANTED"
if allowance_type in cls.ADDITIONAL_TIME_GRANTED:
if not allowance_value.isdigit():
return False
return True
@classmethod
def get_additional_time_granted(cls, exam_id, user_id):
"""
Helper method to get the additional time granted
......
......@@ -91,7 +91,7 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.disabled_content_id = 'test_disabled_content_id'
self.exam_name = 'Test Exam'
self.user_id = self.user.id
self.key = 'Test Key'
self.key = 'additional_time_granted'
self.value = '10'
self.external_id = 'test_external_id'
self.proctored_exam_id = self._create_proctored_exam()
......
......@@ -1907,7 +1907,7 @@ class TestExamAllowanceView(LoggedInTestCase):
allowance_data = {
'exam_id': proctored_exam.id,
'user_info': self.student_taking_exam.username,
'key': 'a_key',
'key': 'additional_time_granted',
'value': 'invalid_value'
}
response = self.client.put(
......
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