Commit 38ee5d8f by chrisndodge

Merge pull request #56 from edx/cdodge/add-submitted-status

Cdodge/add submitted status
parents f22b9b30 a4f53d4b
...@@ -168,7 +168,7 @@ def remove_allowance_for_user(exam_id, user_id, key): ...@@ -168,7 +168,7 @@ def remove_allowance_for_user(exam_id, user_id, key):
student_allowance.delete() student_allowance.delete()
def _update_exam_attempt_status(attempt): def _check_for_attempt_timeout(attempt):
""" """
Helper method to see if the status of an Helper method to see if the status of an
exam needs to be updated, e.g. timeout exam needs to be updated, e.g. timeout
...@@ -190,10 +190,12 @@ def _update_exam_attempt_status(attempt): ...@@ -190,10 +190,12 @@ def _update_exam_attempt_status(attempt):
has_time_expired = now_utc > expires_at has_time_expired = now_utc > expires_at
if has_time_expired: if has_time_expired:
exam_attempt_obj = ProctoredExamStudentAttempt.objects.get_exam_attempt_by_id(attempt['id']) update_attempt_status(
exam_attempt_obj.status = ProctoredExamStudentAttemptStatus.timed_out attempt['proctored_exam']['id'],
exam_attempt_obj.save() attempt['user']['id'],
attempt = ProctoredExamStudentAttemptSerializer(exam_attempt_obj).data ProctoredExamStudentAttemptStatus.timed_out
)
attempt = get_exam_attempt_by_id(attempt['id'])
return attempt return attempt
...@@ -204,7 +206,7 @@ def _get_exam_attempt(exam_attempt_obj): ...@@ -204,7 +206,7 @@ def _get_exam_attempt(exam_attempt_obj):
""" """
serialized_attempt_obj = ProctoredExamStudentAttemptSerializer(exam_attempt_obj) serialized_attempt_obj = ProctoredExamStudentAttemptSerializer(exam_attempt_obj)
attempt = serialized_attempt_obj.data if exam_attempt_obj else None attempt = serialized_attempt_obj.data if exam_attempt_obj else None
attempt = _update_exam_attempt_status(attempt) attempt = _check_for_attempt_timeout(attempt)
return attempt return attempt
...@@ -424,13 +426,18 @@ def update_attempt_status(exam_id, user_id, to_status): ...@@ -424,13 +426,18 @@ def update_attempt_status(exam_id, user_id, to_status):
# see if the status transition this changes credit requirement status # see if the status transition this changes credit requirement status
update_credit = to_status in [ update_credit = to_status in [
ProctoredExamStudentAttemptStatus.verified, ProctoredExamStudentAttemptStatus.rejected, ProctoredExamStudentAttemptStatus.verified, ProctoredExamStudentAttemptStatus.rejected,
ProctoredExamStudentAttemptStatus.declined, ProctoredExamStudentAttemptStatus.not_reviewed ProctoredExamStudentAttemptStatus.declined, ProctoredExamStudentAttemptStatus.not_reviewed,
ProctoredExamStudentAttemptStatus.submitted
] ]
if update_credit: if update_credit:
exam = get_exam_by_id(exam_id) exam = get_exam_by_id(exam_id)
verification = 'satisfied' if to_status == ProctoredExamStudentAttemptStatus.verified \ if to_status == ProctoredExamStudentAttemptStatus.verified:
else 'failed' verification = 'satisfied'
elif to_status == ProctoredExamStudentAttemptStatus.submitted:
verification = 'submitted'
else:
verification = 'failed'
credit_service.set_credit_requirement_status( credit_service.set_credit_requirement_status(
user_id=exam_attempt_obj.user_id, user_id=exam_attempt_obj.user_id,
course_key_or_id=exam['course_id'], course_key_or_id=exam['course_id'],
......
...@@ -31,6 +31,7 @@ from edx_proctoring.api import ( ...@@ -31,6 +31,7 @@ from edx_proctoring.api import (
is_feature_enabled, is_feature_enabled,
mark_exam_attempt_timeout, mark_exam_attempt_timeout,
mark_exam_attempt_as_ready, mark_exam_attempt_as_ready,
update_attempt_status,
) )
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredExamAlreadyExists, ProctoredExamAlreadyExists,
...@@ -51,6 +52,9 @@ from .utils import ( ...@@ -51,6 +52,9 @@ from .utils import (
LoggedInTestCase, LoggedInTestCase,
) )
from edx_proctoring.tests.test_services import MockCreditService
from edx_proctoring.runtime import set_runtime_service, get_runtime_service
class ProctoredExamApiTests(LoggedInTestCase): class ProctoredExamApiTests(LoggedInTestCase):
""" """
...@@ -92,6 +96,8 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -92,6 +96,8 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.start_a_practice_exam_msg = 'Would you like to take %s as a practice proctored exam?' self.start_a_practice_exam_msg = 'Would you like to take %s as a practice proctored exam?'
self.practice_exam_submitted_msg = 'You have submitted this practice proctored exam' self.practice_exam_submitted_msg = 'You have submitted this practice proctored exam'
set_runtime_service('credit', MockCreditService())
def _create_proctored_exam(self): def _create_proctored_exam(self):
""" """
Calls the api's create_exam to create an exam object. Calls the api's create_exam to create an exam object.
...@@ -1030,3 +1036,24 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -1030,3 +1036,24 @@ class ProctoredExamApiTests(LoggedInTestCase):
} }
) )
self.assertIn(self.timed_exam_completed_msg, rendered_response) self.assertIn(self.timed_exam_completed_msg, rendered_response)
def test_submitted_credit_state(self):
"""
Verify that putting an attempt into the submitted state will also mark
the credit requirement as submitted
"""
exam_attempt = self._create_started_exam_attempt()
update_attempt_status(
exam_attempt.proctored_exam_id,
self.user.id,
ProctoredExamStudentAttemptStatus.submitted
)
credit_service = get_runtime_service('credit')
credit_status = credit_service.get_credit_state(self.user.id, exam_attempt.proctored_exam.course_id)
self.assertEqual(len(credit_status['credit_requirement_status']), 1)
self.assertEqual(
credit_status['credit_requirement_status'][0]['status'],
'submitted'
)
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