Commit a7f4c56a by Afzal Wali Committed by Muhammad Shoaib

tests

parent 51c79046
...@@ -306,6 +306,7 @@ def stop_exam_attempt(exam_id, user_id): ...@@ -306,6 +306,7 @@ def stop_exam_attempt(exam_id, user_id):
exam_attempt_obj.save() exam_attempt_obj.save()
return exam_attempt_obj.id return exam_attempt_obj.id
def remove_exam_attempt_by_id(attempt_id): def remove_exam_attempt_by_id(attempt_id):
""" """
Removes an exam attempt given the attempt id. Removes an exam attempt given the attempt id.
...@@ -323,6 +324,7 @@ def remove_exam_attempt_by_id(attempt_id): ...@@ -323,6 +324,7 @@ def remove_exam_attempt_by_id(attempt_id):
existing_attempt.delete_exam_attempt() existing_attempt.delete_exam_attempt()
def get_all_exams_for_course(course_id): def get_all_exams_for_course(course_id):
""" """
This method will return all exams for a course. This will return a list This method will return all exams for a course. This will return a list
......
...@@ -21,8 +21,8 @@ from edx_proctoring.api import ( ...@@ -21,8 +21,8 @@ from edx_proctoring.api import (
get_student_view, get_student_view,
get_allowances_for_course, get_allowances_for_course,
get_all_exams_for_course, get_all_exams_for_course,
get_exam_attempt_by_id get_exam_attempt_by_id,
) remove_exam_attempt_by_id)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredExamAlreadyExists, ProctoredExamAlreadyExists,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -336,6 +336,19 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -336,6 +336,19 @@ class ProctoredExamApiTests(LoggedInTestCase):
) )
self.assertEqual(proctored_exam_student_attempt.id, proctored_exam_attempt_id) self.assertEqual(proctored_exam_student_attempt.id, proctored_exam_attempt_id)
def test_remove_exam_attempt(self):
"""
Calling the api remove function removes the attempt.
"""
with self.assertRaises(StudentExamAttemptDoesNotExistsException):
remove_exam_attempt_by_id(9999)
proctored_exam_student_attempt = self._create_unstarted_exam_attempt()
remove_exam_attempt_by_id(proctored_exam_student_attempt.id)
with self.assertRaises(StudentExamAttemptDoesNotExistsException):
remove_exam_attempt_by_id(proctored_exam_student_attempt.id)
def test_stop_a_non_started_exam(self): def test_stop_a_non_started_exam(self):
""" """
Stop an exam attempt that had not started yet. Stop an exam attempt that had not started yet.
......
...@@ -114,6 +114,7 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase): ...@@ -114,6 +114,7 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase):
def test_delete_proctored_exam_attempt(self): # pylint: disable=invalid-name def test_delete_proctored_exam_attempt(self): # pylint: disable=invalid-name
""" """
Deleting the proctored exam attempt creates an entry in the history table.
""" """
proctored_exam = ProctoredExam.objects.create( proctored_exam = ProctoredExam.objects.create(
course_id='test_course', course_id='test_course',
...@@ -137,7 +138,7 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase): ...@@ -137,7 +138,7 @@ class ProctoredExamStudentAttemptTests(LoggedInTestCase):
attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=1) attempt_history = ProctoredExamStudentAttemptHistory.objects.filter(user_id=1)
self.assertEqual(len(attempt_history), 0) self.assertEqual(len(attempt_history), 0)
attempt.delete() attempt.delete_exam_attempt()
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)
...@@ -433,6 +433,46 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase): ...@@ -433,6 +433,46 @@ class TestStudentProctoredExamAttempt(LoggedInTestCase):
self.assertIsNotNone(response_data['started_at']) self.assertIsNotNone(response_data['started_at'])
self.assertIsNone(response_data['completed_at']) self.assertIsNone(response_data['completed_at'])
def test_remove_attempt(self):
"""
Confirms that an attempt can be removed
"""
# Create an exam.
proctored_exam = ProctoredExam.objects.create(
course_id='a/b/c',
content_id='test_content',
exam_name='Test Exam',
external_id='123aXqe3',
time_limit_mins=90
)
response = self.client.delete(
reverse('edx_proctoring.proctored_exam.attempt', args=[1])
)
self.assertEqual(response.status_code, 400)
attempt_data = {
'exam_id': proctored_exam.id,
'external_id': proctored_exam.external_id,
'start_clock': True,
}
response = self.client.post(
reverse('edx_proctoring.proctored_exam.attempt.collection'),
attempt_data
)
self.assertEqual(response.status_code, 200)
response_data = json.loads(response.content)
attempt_id = response_data['exam_attempt_id']
self.assertGreater(attempt_id, 0)
response = self.client.delete(
reverse('edx_proctoring.proctored_exam.attempt', args=[attempt_id])
)
self.assertEqual(response.status_code, 200)
def test_read_others_attempt(self): def test_read_others_attempt(self):
""" """
Confirms that we cnanot read someone elses attempt Confirms that we cnanot read someone elses attempt
......
...@@ -313,7 +313,7 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView): ...@@ -313,7 +313,7 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
) )
@method_decorator(require_staff) @method_decorator(require_staff)
def delete(self, request, attempt_id): def delete(self, request, attempt_id): # pylint: disable=unused-argument
""" """
HTTP DELETE handler. Removes an exam attempt. HTTP DELETE handler. Removes an exam attempt.
""" """
...@@ -339,7 +339,6 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView): ...@@ -339,7 +339,6 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
) )
class StudentProctoredExamAttemptCollection(AuthenticatedAPIView): class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
""" """
Endpoint for the StudentProctoredExamAttempt Endpoint for the StudentProctoredExamAttempt
......
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