Skip to content

Commit

Permalink
Merge pull request #281 from edx/efischer/delete_state
Browse files Browse the repository at this point in the history
Pass requesting user on delete_student_attempt
  • Loading branch information
Eric Fischer committed Mar 10, 2016
2 parents a7dc875 + 5e00da6 commit eaf8a89
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,9 @@ def send_proctoring_attempt_status_email(exam_attempt_obj, course_name):
email.send()


def remove_exam_attempt(attempt_id):
def remove_exam_attempt(attempt_id, requesting_user):
"""
Removes an exam attempt given the attempt id.
Removes an exam attempt given the attempt id. requesting_user is passed through to the instructor_service.
"""

log_msg = (
Expand All @@ -991,7 +991,7 @@ def remove_exam_attempt(attempt_id):
instructor_service = get_runtime_service('instructor')

if instructor_service:
instructor_service.delete_student_attempt(username, course_id, content_id)
instructor_service.delete_student_attempt(username, course_id, content_id, requesting_user=requesting_user)

# see if the status transition this changes credit requirement status
if ProctoredExamStudentAttemptStatus.needs_credit_status_update(to_status):
Expand Down
4 changes: 2 additions & 2 deletions edx_proctoring/backends/tests/test_software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def test_review_on_archived_attempt(self):
)

# now delete the attempt, which puts it into the archive table
remove_exam_attempt(attempt_id)
remove_exam_attempt(attempt_id, requesting_user=self.user)

# now process the report
provider.on_review_callback(json.loads(test_payload))
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_update_archived_attempt(self):
self.assertEqual(attempt['status'], attempt['status'])

# now delete the attempt, which puts it into the archive table
remove_exam_attempt(attempt_id)
remove_exam_attempt(attempt_id, requesting_user=self.user)

review = ProctoredExamSoftwareSecureReview.objects.get(attempt_code=attempt['attempt_code'])

Expand Down
16 changes: 12 additions & 4 deletions edx_proctoring/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,21 @@ def test_remove_exam_attempt(self):
Calling the api remove function removes the attempt.
"""
with self.assertRaises(StudentExamAttemptDoesNotExistsException):
remove_exam_attempt(9999)
remove_exam_attempt(9999, requesting_user=self.user)

proctored_exam_student_attempt = self._create_unstarted_exam_attempt()
remove_exam_attempt(proctored_exam_student_attempt.id)
remove_exam_attempt(proctored_exam_student_attempt.id, requesting_user=self.user)

with self.assertRaises(StudentExamAttemptDoesNotExistsException):
remove_exam_attempt(proctored_exam_student_attempt.id)
remove_exam_attempt(proctored_exam_student_attempt.id, requesting_user=self.user)

def test_remove_no_user(self):
"""
Attempting to remove an exam attempt without providing a requesting user will fail.
"""
proctored_exam_student_attempt = self._create_unstarted_exam_attempt()
with self.assertRaises(UserNotFoundException):
remove_exam_attempt(proctored_exam_student_attempt.id, requesting_user={})

@ddt.data(
(ProctoredExamStudentAttemptStatus.verified, 'satisfied'),
Expand Down Expand Up @@ -868,7 +876,7 @@ def test_remove_exam_attempt_with_status(self, to_status, requirement_status):
)

# now remove exam attempt which calls the credit service method 'remove_credit_requirement_status'
remove_exam_attempt(exam_attempt.proctored_exam_id)
remove_exam_attempt(exam_attempt.proctored_exam_id, requesting_user=self.user)

# make sure the credit requirement status is no longer there
credit_status = credit_service.get_credit_state(self.user.id, exam_attempt.proctored_exam.course_id)
Expand Down
7 changes: 6 additions & 1 deletion edx_proctoring/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from edx_proctoring.services import (
ProctoringService
)
from edx_proctoring.exceptions import UserNotFoundException
from edx_proctoring import api as edx_proctoring_api
import types

Expand Down Expand Up @@ -111,10 +112,14 @@ def __init__(self, is_user_course_staff=True):
"""
self.is_user_course_staff = is_user_course_staff

def delete_student_attempt(self, student_identifier, course_id, content_id): # pylint: disable=unused-argument
# pylint: disable=unused-argument
def delete_student_attempt(self, student_identifier, course_id, content_id, requesting_user):
"""
Mock implementation
"""
# Ensure that this method was called with a real user object
if not hasattr(requesting_user, 'id'):
raise UserNotFoundException
return True

def is_course_staff(self, user, course_id):
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def delete(self, request, attempt_id): # pylint: disable=unused-argument
)
raise StudentExamAttemptDoesNotExistsException(err_msg)

remove_exam_attempt(attempt_id)
remove_exam_attempt(attempt_id, request.user)
return Response()

except ProctoredBaseException, ex:
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.12.13',
version='0.12.14',
description='Proctoring subsystem for Open edX',
long_description=open('README.md').read(),
author='edX',
Expand Down

0 comments on commit eaf8a89

Please sign in to comment.