diff --git a/lms/djangoapps/instructor/services.py b/lms/djangoapps/instructor/services.py index 39c26605eec7d8174735b28272b0f45f026a3853..3a9e380c4383110d7caea2dd12c9deba73f11884 100644 --- a/lms/djangoapps/instructor/services.py +++ b/lms/djangoapps/instructor/services.py @@ -9,7 +9,6 @@ from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext as _ from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import CourseLocator import lms.djangoapps.instructor.enrollment as enrollment from common.djangoapps.student import auth @@ -123,17 +122,24 @@ class InstructorService: tags = ["proctoring"] create_zendesk_ticket(requester_name, email, subject, body, tags) - def get_proctoring_escalation_email(self, course_key): + def get_proctoring_escalation_email(self, course_id): """ Returns the proctoring escalation email for a course, or None if not given. Example arguments: - * course_key (String): 'block-v1:edX+DemoX+Demo_Course' + * course_id (String): 'block-v1:edX+DemoX+Demo_Course' """ - # Convert course key into id - course_id = CourseLocator.from_string(course_key) - course = modulestore().get_course(course_id) + try: + # Convert course id into course key + course_key = CourseKey.from_string(course_id) + except AttributeError: + # If a course key object is given instead of a string, ensure that it is used + course_key = course_id + course = modulestore().get_course(course_key) if course is None: - raise ObjectDoesNotExist('Course not found for course_key {course_key}.') + raise ObjectDoesNotExist( + 'Could not find proctoring escalation email for course_id={course_id}.' + ' This course does not exist.'.format(course_id=course_id) + ) return course.proctoring_escalation_email diff --git a/lms/djangoapps/instructor/tests/test_services.py b/lms/djangoapps/instructor/tests/test_services.py index ba298934ee05b4ed017516fce575cf1b7d8108a8..c2161f90d60165f169bcde299b330a804418dc2a 100644 --- a/lms/djangoapps/instructor/tests/test_services.py +++ b/lms/djangoapps/instructor/tests/test_services.py @@ -175,9 +175,16 @@ class InstructorServiceTests(SharedModuleStoreTestCase): expected_body = body.format(**args) mock_create_zendesk_ticket.assert_called_with(requester_name, email, subject, expected_body, tags) - def test_get_proctoring_escalation_email(self): + def test_get_proctoring_escalation_email_from_course_key(self): """ - Test that it returns the correct proctoring escalation email + Test that it returns the correct proctoring escalation email from a course key object + """ + email = self.service.get_proctoring_escalation_email(self.course.id) + assert email == self.email + + def test_get_proctoring_escalation_email_from_course_id(self): + """ + Test that it returns the correct proctoring escalation email from a course id string """ email = self.service.get_proctoring_escalation_email(str(self.course.id)) assert email == self.email