Integration of edx_proctoring into the LMS
This commit is contained in:
@@ -16,6 +16,7 @@ import xmodule.graders as xmgraders
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from microsite_configuration import microsite
|
||||
from student.models import CourseEnrollmentAllowed
|
||||
from edx_proctoring.api import get_all_exam_attempts
|
||||
|
||||
|
||||
STUDENT_FEATURES = ('id', 'username', 'first_name', 'last_name', 'is_staff', 'email')
|
||||
@@ -243,6 +244,26 @@ def list_may_enroll(course_key, features):
|
||||
return [extract_student(student, features) for student in may_enroll_and_unenrolled]
|
||||
|
||||
|
||||
def get_proctored_exam_results(course_key, features):
|
||||
"""
|
||||
Return info about proctored exam results in a course as a dict.
|
||||
"""
|
||||
def extract_student(exam_attempt, features):
|
||||
"""
|
||||
Build dict containing information about a single student exam_attempt.
|
||||
"""
|
||||
proctored_exam = dict(
|
||||
(feature, exam_attempt.get(feature)) for feature in features if feature in exam_attempt
|
||||
)
|
||||
proctored_exam.update({'exam_name': exam_attempt.get('proctored_exam').get('exam_name')})
|
||||
proctored_exam.update({'user_email': exam_attempt.get('user').get('email')})
|
||||
|
||||
return proctored_exam
|
||||
|
||||
exam_attempts = get_all_exam_attempts(course_key)
|
||||
return [extract_student(exam_attempt, features) for exam_attempt in exam_attempts]
|
||||
|
||||
|
||||
def coupon_codes_features(features, coupons_list, course_id):
|
||||
"""
|
||||
Return list of Coupon Codes as dictionaries.
|
||||
|
||||
@@ -3,6 +3,9 @@ Tests for instructor.basic
|
||||
"""
|
||||
|
||||
import json
|
||||
import datetime
|
||||
from django.db.models import Q
|
||||
import pytz
|
||||
from student.models import CourseEnrollment, CourseEnrollmentAllowed
|
||||
from django.core.urlresolvers import reverse
|
||||
from mock import patch
|
||||
@@ -16,16 +19,14 @@ from course_modes.models import CourseMode
|
||||
from instructor_analytics.basic import (
|
||||
sale_record_features, sale_order_record_features, enrolled_students_features,
|
||||
course_registration_features, coupon_codes_features, list_may_enroll,
|
||||
AVAILABLE_FEATURES, STUDENT_FEATURES, PROFILE_FEATURES
|
||||
)
|
||||
AVAILABLE_FEATURES, STUDENT_FEATURES, PROFILE_FEATURES,
|
||||
get_proctored_exam_results)
|
||||
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
|
||||
from courseware.tests.factories import InstructorFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
import datetime
|
||||
from django.db.models import Q
|
||||
import pytz
|
||||
from edx_proctoring.api import create_exam
|
||||
from edx_proctoring.models import ProctoredExamStudentAttempt
|
||||
|
||||
|
||||
class TestAnalyticsBasic(ModuleStoreTestCase):
|
||||
@@ -127,6 +128,40 @@ class TestAnalyticsBasic(ModuleStoreTestCase):
|
||||
self.assertEqual(student.keys(), ['email'])
|
||||
self.assertIn(student['email'], email_adresses)
|
||||
|
||||
def test_get_student_exam_attempt_features(self):
|
||||
query_features = [
|
||||
'created',
|
||||
'modified',
|
||||
'started_at',
|
||||
'exam_name',
|
||||
'user_email',
|
||||
'completed_at',
|
||||
'external_id',
|
||||
'allowed_time_limit_mins',
|
||||
'status',
|
||||
'attempt_code',
|
||||
'is_sample_attempt',
|
||||
]
|
||||
|
||||
proctored_exam_id = create_exam(self.course_key, 'Test Content', 'Test Exam', 1)
|
||||
ProctoredExamStudentAttempt.create_exam_attempt(
|
||||
proctored_exam_id, self.users[0].id, '', 1,
|
||||
'Test Code 1', True, False, 'ad13'
|
||||
)
|
||||
ProctoredExamStudentAttempt.create_exam_attempt(
|
||||
proctored_exam_id, self.users[1].id, '', 2,
|
||||
'Test Code 2', True, False, 'ad13'
|
||||
)
|
||||
ProctoredExamStudentAttempt.create_exam_attempt(
|
||||
proctored_exam_id, self.users[2].id, '', 3,
|
||||
'Test Code 3', True, False, 'asd'
|
||||
)
|
||||
|
||||
proctored_exam_attempts = get_proctored_exam_results(self.course_key, query_features)
|
||||
self.assertEqual(len(proctored_exam_attempts), 3)
|
||||
for proctored_exam_attempt in proctored_exam_attempts:
|
||||
self.assertEqual(set(proctored_exam_attempt.keys()), set(query_features))
|
||||
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_PAID_COURSE_REGISTRATION': True})
|
||||
class TestCourseSaleRecordsAnalyticsBasic(ModuleStoreTestCase):
|
||||
|
||||
Reference in New Issue
Block a user