Skip to content

Commit

Permalink
don't assume a single Attempt History record
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dodge committed Sep 30, 2015
1 parent ffd2861 commit 950729d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
14 changes: 10 additions & 4 deletions edx_proctoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,16 @@ def get_exam_attempt_by_code(cls, attempt_code):
Returns the Student Exam Attempt object if found
else Returns None.
"""
try:
exam_attempt_obj = cls.objects.get(attempt_code=attempt_code)
except ObjectDoesNotExist: # pylint: disable=no-member
exam_attempt_obj = None
# NOTE: compared to the ProctoredExamAttempt table
# we can have multiple rows with the same attempt_code
# So, just return the first one (most recent) if
# 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

class Meta:
Expand Down
24 changes: 24 additions & 0 deletions edx_proctoring/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ def test_delete_proctored_exam_attempt(self): # pylint: disable=invalid-name
attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=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):
"""
Test to get all the exam attempts for a course
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_requirements(*requirements_paths):

setup(
name='edx-proctoring',
version='0.10.1',
version='0.9.15',
description='Proctoring subsystem for Open edX',
long_description=open('README.md').read(),
author='edX',
Expand Down

0 comments on commit 950729d

Please sign in to comment.