Commit 3e4f500a by Chris Dodge

Add API method to get a list of all exams for a course

parent b17b841b
...@@ -219,6 +219,17 @@ def stop_exam_attempt(exam_id, user_id): ...@@ -219,6 +219,17 @@ def stop_exam_attempt(exam_id, user_id):
return exam_attempt_obj.id return exam_attempt_obj.id
def get_all_exams_for_course(course_id):
"""
This method will return all exams for a course. This will return a list
of dictionaries, whose schema is the same as what is returned in
get_exam_by_id
"""
exams = ProctoredExam.get_all_exams_for_course(course_id)
return [ProctoredExamSerializer(proctored_exam).data for proctored_exam in exams]
def get_active_exams_for_user(user_id, course_id=None): def get_active_exams_for_user(user_id, course_id=None):
""" """
This method will return a list of active exams for the user, This method will return a list of active exams for the user,
...@@ -277,9 +288,17 @@ def get_student_view(user_id, course_id, content_id, context): ...@@ -277,9 +288,17 @@ def get_student_view(user_id, course_id, content_id, context):
exam_id = None exam_id = None
try: try:
exam = get_exam_by_content_id(course_id, content_id) exam = get_exam_by_content_id(course_id, content_id)
if not exam['is_active']:
# Exam is no longer active
# Note, we don't hard delete exams since we need to retain
# data
return None
exam_id = exam['id'] exam_id = exam['id']
is_proctored = exam['is_proctored'] is_proctored = exam['is_proctored']
except ProctoredExamNotFoundException: except ProctoredExamNotFoundException:
# This really shouldn't happen
# as Studio will be setting this up
is_proctored = context.get('is_proctored', False) is_proctored = context.get('is_proctored', False)
exam_id = create_exam( exam_id = create_exam(
course_id=course_id, course_id=course_id,
......
...@@ -65,6 +65,13 @@ class ProctoredExam(TimeStampedModel): ...@@ -65,6 +65,13 @@ class ProctoredExam(TimeStampedModel):
proctored_exam = None proctored_exam = None
return proctored_exam return proctored_exam
@classmethod
def get_all_exams_for_course(cls, course_id):
"""
Returns all exams for a give course
"""
return cls.objects.filter(course_id=course_id)
class ProctoredExamStudentAttempt(TimeStampedModel): class ProctoredExamStudentAttempt(TimeStampedModel):
""" """
......
...@@ -16,6 +16,7 @@ from edx_proctoring.api import ( ...@@ -16,6 +16,7 @@ from edx_proctoring.api import (
get_exam_attempt, get_exam_attempt,
create_exam_attempt, create_exam_attempt,
get_student_view, get_student_view,
get_all_exams_for_course,
) )
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredExamAlreadyExists, ProctoredExamAlreadyExists,
...@@ -152,6 +153,12 @@ class ProctoredExamApiTests(LoggedInTestCase): ...@@ -152,6 +153,12 @@ class ProctoredExamApiTests(LoggedInTestCase):
self.assertEqual(proctored_exam['content_id'], self.content_id) self.assertEqual(proctored_exam['content_id'], self.content_id)
self.assertEqual(proctored_exam['exam_name'], self.exam_name) self.assertEqual(proctored_exam['exam_name'], self.exam_name)
exams = get_all_exams_for_course(self.course_id)
self.assertEqual(len(exams), 1)
self.assertEqual(exams[0]['course_id'], self.course_id)
self.assertEqual(exams[0]['content_id'], self.content_id)
self.assertEqual(exams[0]['exam_name'], self.exam_name)
def test_get_invalid_proctored_exam(self): def test_get_invalid_proctored_exam(self):
""" """
test to get the exam by the invalid exam_id which will test to get the exam by the invalid exam_id which will
......
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