Commit 2901ec66 by Chris Dodge

don't assume a single Attempt History record

parent 4dc6baca
...@@ -518,10 +518,16 @@ class ProctoredExamStudentAttemptHistory(TimeStampedModel): ...@@ -518,10 +518,16 @@ class ProctoredExamStudentAttemptHistory(TimeStampedModel):
Returns the Student Exam Attempt object if found Returns the Student Exam Attempt object if found
else Returns None. else Returns None.
""" """
try: # NOTE: compared to the ProctoredExamAttempt table
exam_attempt_obj = cls.objects.get(attempt_code=attempt_code) # we can have multiple rows with the same attempt_code
except ObjectDoesNotExist: # pylint: disable=no-member # So, just return the first one (most recent) if
exam_attempt_obj = None # there are any
exam_attempt_obj = None
items = cls.objects.filter(attempt_code=attempt_code).order_by("-created")
if items:
exam_attempt_obj = items[0]
return exam_attempt_obj return exam_attempt_obj
class Meta: class Meta:
......
...@@ -150,6 +150,30 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase): ...@@ -150,6 +150,30 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase):
attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=1) attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=1)
self.assertEqual(len(attempt_history), 1) self.assertEqual(len(attempt_history), 1)
# make sure we can ready it back with helper class method
deleted_item = ProctoredExamStudentAttemptHistory.get_exam_attempt_by_code("123456")
self.assertEqual(deleted_item.student_name, "John. D")
# re-create and delete again using same attempt_cde
attempt = ProctoredExamStudentAttempt.objects.create(
proctored_exam_id=proctored_exam.id,
user_id=1,
student_name="John. D Updated",
allowed_time_limit_mins=10,
attempt_code="123456",
taking_as_proctored=True,
is_sample_attempt=True,
external_id=1
)
attempt.delete_exam_attempt()
attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=1)
self.assertEqual(len(attempt_history), 2)
deleted_item = ProctoredExamStudentAttemptHistory.get_exam_attempt_by_code("123456")
self.assertEqual(deleted_item.student_name, "John. D Updated")
def test_get_exam_attempts(self): def test_get_exam_attempts(self):
""" """
Test to get all the exam attempts for a course Test to get all the exam attempts for a course
......
...@@ -34,7 +34,7 @@ def load_requirements(*requirements_paths): ...@@ -34,7 +34,7 @@ def load_requirements(*requirements_paths):
setup( setup(
name='edx-proctoring', name='edx-proctoring',
version='0.9.14', version='0.9.15',
description='Proctoring subsystem for Open edX', description='Proctoring subsystem for Open edX',
long_description=open('README.md').read(), long_description=open('README.md').read(),
author='edX', author='edX',
......
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