From e3080a52ba54e0131932d6315b3baa5ad7ff9eba Mon Sep 17 00:00:00 2001 From: attiyaishaque Date: Wed, 30 Aug 2017 11:17:55 +0500 Subject: [PATCH] EDUCATOR-1256 Fix 500 error when user is not enrolled. --- edx_proctoring/api.py | 2 +- edx_proctoring/tests/test_student_view.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/edx_proctoring/api.py b/edx_proctoring/api.py index 4c09298dbc7..45a8a811721 100644 --- a/edx_proctoring/api.py +++ b/edx_proctoring/api.py @@ -1896,7 +1896,7 @@ def get_student_view(user_id, course_id, content_id, # call service to get course end date. credit_state = credit_service.get_credit_state(user_id, course_id, return_course_info=True) - course_end_date = credit_state.get('course_end_date', None) + course_end_date = credit_state.get('course_end_date') if credit_state else None exam_id = None try: diff --git a/edx_proctoring/tests/test_student_view.py b/edx_proctoring/tests/test_student_view.py index 434e718fd8f..33a531f3bd6 100644 --- a/edx_proctoring/tests/test_student_view.py +++ b/edx_proctoring/tests/test_student_view.py @@ -29,7 +29,7 @@ ) from edx_proctoring.runtime import set_runtime_service -from .test_services import MockCreditServiceWithCourseEndDate +from .test_services import MockCreditServiceWithCourseEndDate, MockCreditServiceNone from .utils import ProctoredExamTestCase @@ -388,6 +388,24 @@ def test_get_disabled_student_view(self): ) ) + def test_student_response_without_credit_state(self): + """ + Test that response is not None for users who are not enrolled. + """ + set_runtime_service('credit', MockCreditServiceNone()) + rendered_response = get_student_view( + user_id=self.user_id, + course_id=self.course_id, + content_id=self.content_id, + context={ + 'is_proctored': True, + 'display_name': self.exam_name, + 'default_time_limit_mins': 90 + }, + user_role='student' + ) + self.assertIsNotNone(rendered_response) + @ddt.data(False, True) def test_get_studentview_unstarted_exam(self, allow_proctoring_opt_out): """