Skip to content

Commit

Permalink
fix: update tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Oct 3, 2024
1 parent 9694cc1 commit 2c1033d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ def update_attempt_status(attempt_id, to_status,
if email:
try:
email.send()
except Exception as err: # pylint: disable=broad-except
except Exception as err:
log.exception(
('Exception occurred while trying to send proctoring attempt '
'status email for user_id=%(user_id)s in course_id=%(course_id)s -- %(err)s'),
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/backends/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def on_exam_saved(self, exam):
try:
response = self.session.post(url, json=exam)
data = response.json()
except Exception as exc: # pylint: disable=broad-except
except Exception as exc:
if response:
if hasattr(exc, 'response') and exc.response is not None:
content = exc.response.content
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/backends/software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_instructor_url(
# reformat video url as per MST-871 findings
reformatted_url = decrypted_video_url.replace('DirectLink-Generic', 'DirectLink-HTML5')
return reformatted_url
except Exception as err: # pylint: disable=broad-except
except Exception as err:
log.exception(
'Could not decrypt video url for attempt_id=%(attempt_id)s '
'due to the following error: %(error_string)s',
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def is_in_reviewer_group(user, attempt):
return user.groups.filter(name=backend_group).exists()


# pylint: disable=unsupported-binary-operation
# pylint: disable-next=unsupported-binary-operation
rules.add_perm('edx_proctoring.can_review_attempt', is_in_reviewer_group | rules.is_staff)
5 changes: 5 additions & 0 deletions edx_proctoring/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,11 @@ def test_dashboard_availability(self):
# backend with a dashboard
self.assertTrue(is_backend_dashboard_available(self.course_id))

@patch('edx_proctoring.api.get_backend_provider')
def test_dashboard_availability_no_provider(self, mock_get_backend):
mock_get_backend.side_effect = NotImplementedError()
self.assertFalse(is_backend_dashboard_available(self.course_id))

def test_does_provider_support_onboarding(self):
self.assertTrue(does_backend_support_onboarding('test'))
self.assertFalse(does_backend_support_onboarding('mock'))
Expand Down
22 changes: 22 additions & 0 deletions edx_proctoring/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,18 @@ def test_no_onboarding_exam(self):
message = 'There is no onboarding exam related to this course id.'
self.assertEqual(response_data['detail'], message)

@patch('edx_proctoring.views.get_backend_provider')
def test_invalid_backend(self, mock_get_backend):
mock_get_backend.side_effect = NotImplementedError()
response = self.client.get(
reverse('edx_proctoring:user_onboarding.status')
+ f'?course_id={self.course_id}'
)
self.assertEqual(response.status_code, 404)
response_data = json.loads(response.content.decode('utf-8'))
message = 'There is no onboarding exam related to this course id.'
self.assertEqual(response_data['detail'], message)

@override_settings(LEARNING_MICROFRONTEND_URL='https://learningmfe')
def test_onboarding_mfe_link(self):
"""
Expand Down Expand Up @@ -1518,6 +1530,16 @@ def test_backend_does_not_support_onboarding(self):
self.assertEqual(response.status_code, 404)
test_backend.supports_onboarding = previous_value

@patch('edx_proctoring.views.get_backend_provider')
def test_invalid_backend(self, mock_get_backend):
mock_get_backend.side_effect = NotImplementedError()
response = self.client.get(reverse(
'edx_proctoring:user_onboarding.status.course',
kwargs={'course_id': 'a/b/c'}
)
)
self.assertEqual(response.status_code, 404)

def test_multiple_onboarding_exams(self):
onboarding_exam_2_id = create_exam(
course_id=self.course_id,
Expand Down
16 changes: 4 additions & 12 deletions edx_proctoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class StudentOnboardingStatusView(ProctoredAPIView):
* 'onboarding_past_due': Whether the onboarding exam is past due. All onboarding exams in the course must
be past due in order for onboarding_past_due to be true.
"""
def get(self, request):
def get(self, request): # pylint: disable=too-many-statements
"""
HTTP GET handler. Returns the learner's onboarding status.
"""
Expand Down Expand Up @@ -679,7 +679,7 @@ def get(self, request):
onboarding_exams = list(ProctoredExam.get_practice_proctored_exams_for_course(course_id).order_by('-created'))
provider = None
try:
provider = get_backend_provider(name=onboarding_exams[0].backend)
provider = get_backend_provider(name=onboarding_exams[0].backend) if onboarding_exams else None
except NotImplementedError:
logging.exception(
'No proctoring backend configured for backend=%(backend)s',
Expand Down Expand Up @@ -860,7 +860,7 @@ def get(self, request, course_id):
.order_by('-created').first())
provider = None
try:
provider = get_backend_provider(name=onboarding_exam.backend)
provider = get_backend_provider(name=onboarding_exam.backend) if onboarding_exam else None
except NotImplementedError:
logging.exception(
'No proctoring backend configured for backend=%(backend)s',
Expand Down Expand Up @@ -2140,15 +2140,7 @@ def get(self, request, course_id, exam_id=None):
continue

exam_backend_name = exam.get('backend')
try:
backend = get_backend_provider(name=exam_backend_name)
except NotImplementedError:
logging.exception(
'No proctoring backend configured for backend=%(backend)s',
{
'backend': exam_backend_name,
}
)
backend = get_backend_provider(name=exam_backend_name)
if existing_backend_name and exam_backend_name != existing_backend_name:
# In this case, what are we supposed to do?!
# It should not be possible to get in this state, because
Expand Down

0 comments on commit 2c1033d

Please sign in to comment.