From 19af988b5b8fcec42c226740b576e1c26383b98c Mon Sep 17 00:00:00 2001 From: Matt Hughes Date: Mon, 27 Sep 2021 16:39:48 -0400 Subject: [PATCH] chore: fix pylint errors in test files for string formatting JIRA:MST-1061 --- edx_proctoring/backends/tests/test_backend.py | 6 +- .../backends/tests/test_software_secure.py | 9 +- edx_proctoring/tests/test_api.py | 10 +- edx_proctoring/tests/test_email.py | 19 ++-- edx_proctoring/tests/test_mfe_views.py | 13 +-- edx_proctoring/tests/test_models.py | 8 +- edx_proctoring/tests/test_reviews.py | 2 +- edx_proctoring/tests/test_student_view.py | 19 ++-- edx_proctoring/tests/test_views.py | 92 +++++++++---------- edx_proctoring/tests/test_workerconfig.py | 2 +- edx_proctoring/tests/utils.py | 2 +- 11 files changed, 85 insertions(+), 97 deletions(-) diff --git a/edx_proctoring/backends/tests/test_backend.py b/edx_proctoring/backends/tests/test_backend.py index 662c81ccf0c..2748d63445d 100644 --- a/edx_proctoring/backends/tests/test_backend.py +++ b/edx_proctoring/backends/tests/test_backend.py @@ -91,11 +91,11 @@ def on_exam_saved(self, exam): # pylint: disable=unused-argument def get_instructor_url(self, course_id, user, exam_id=None, attempt_id=None, show_configuration_dashboard=False): "Return a fake instructor url" - url = '/instructor/%s/' % course_id + url = f'/instructor/{course_id}/' if exam_id: - url += '?exam=%s' % exam_id + url += f'?exam={exam_id}' if attempt_id: - url += '&attempt=%s' % attempt_id + url += f'&attempt={attempt_id}' if show_configuration_dashboard: url += '&config=true' diff --git a/edx_proctoring/backends/tests/test_software_secure.py b/edx_proctoring/backends/tests/test_software_secure.py index 84714d2a009..fada6e25775 100644 --- a/edx_proctoring/backends/tests/test_software_secure.py +++ b/edx_proctoring/backends/tests/test_software_secure.py @@ -269,10 +269,7 @@ def assert_get_payload_mock(self, exam, context): # assert that this is in the 'reviewerNotes' field that is passed to SoftwareSecure expected = context['review_policy'] if review_policy_exception: - expected = '{base}; {exception}'.format( - base=expected, - exception=review_policy_exception - ) + expected = f'{expected}; {review_policy_exception}' test_self.assertEqual(result['reviewerNotes'], expected) return result @@ -331,8 +328,8 @@ def assert_get_payload_mock_no_policy(self, exam, context): for illegal_char in SOFTWARE_SECURE_INVALID_CHARS: exam_id = create_exam( course_id='foo/bar/baz', - content_id='content with {}'.format(illegal_char), - exam_name='Sample Exam with {} character'.format(illegal_char), + content_id=f'content with {illegal_char}', + exam_name=f'Sample Exam with {illegal_char} character', time_limit_mins=10, is_proctored=True, backend='software_secure', diff --git a/edx_proctoring/tests/test_api.py b/edx_proctoring/tests/test_api.py index 826bc243b41..3d98f48474a 100644 --- a/edx_proctoring/tests/test_api.py +++ b/edx_proctoring/tests/test_api.py @@ -2932,7 +2932,7 @@ def test_exam_configuration_dashboard_url(self): ) self.assertEqual( get_exam_configuration_dashboard_url(self.course_id, 'test_content_2'), - '/edx_proctoring/v1/instructor/a/b/c/{}?config=true'.format(exam_id) + f'/edx_proctoring/v1/instructor/a/b/c/{exam_id}?config=true' ) def test_clear_onboarding_errors(self): @@ -3482,9 +3482,9 @@ def test_get_exam_attempt_data(self, is_proctored_exam, is_learning_mfe): exam_id = self.timed_exam_id if not is_proctored_exam else self.proctored_exam_id attempt_data = get_exam_attempt_data(exam_id, attempt.id, is_learning_mfe) content_id = self.content_id if is_proctored_exam else self.content_id_timed - expected_exam_url = '{}/course/{}/{}'.format( - settings.LEARNING_MICROFRONTEND_URL, self.course_id, content_id - ) if is_learning_mfe else reverse('jump_to', args=[self.course_id, content_id]) + expected_exam_url = (f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{content_id}' + if is_learning_mfe + else reverse('jump_to', args=[self.course_id, content_id])) assert attempt_data assert 'attempt_id' in attempt_data @@ -3644,7 +3644,7 @@ def test_check_prerequisites(self, status, are_satisfied, expected_prerequisites result = check_prerequisites(self.exam, self.user_id) self.assertEqual(result['prerequisite_status']['are_prerequisites_satisifed'], are_satisfied) self.assertEqual( - len(result['prerequisite_status']['{}_prerequisites'.format(status)]), + len(result['prerequisite_status'][f'{status}_prerequisites']), expected_prerequisites_len ) if status == 'declined': diff --git a/edx_proctoring/tests/test_email.py b/edx_proctoring/tests/test_email.py index 3b6c5536a28..22cfa115d21 100644 --- a/edx_proctoring/tests/test_email.py +++ b/edx_proctoring/tests/test_email.py @@ -108,12 +108,8 @@ def test_send_email_failure(self, logger_mock): exam_attempt.refresh_from_db() self.assertEqual(exam_attempt.status, 'submitted') log_format_string = ( - 'Exception occurred while trying to send proctoring attempt ' - 'status email for user_id={user_id} in course_id={course_id} -- {err}'.format( - user_id=self.user_id, - course_id=self.course_id, - err='foo', - ) + f'Exception occurred while trying to send proctoring attempt ' + f'status email for user_id={self.user_id} in course_id={self.course_id} -- foo' ) logger_mock.assert_any_call(log_format_string) @@ -199,9 +195,8 @@ def test_email_template_select(self, status, template_name, select_template_mock ) expected_args = [ - 'emails/proctoring/{backend}/{template_name}'.format( - backend=exam_attempt.proctored_exam.backend, template_name=template_name), - 'emails/{template_name}'.format(template_name=template_name) + f'emails/proctoring/{exam_attempt.proctored_exam.backend}/{template_name}', + f'emails/{template_name}', ] select_template_mock.assert_called_once_with(expected_args) @@ -301,7 +296,7 @@ def test_correct_edx_support_url(self, status, override_email): Test that the correct edX support URL is used in emails. The email should use either the backend specific contact URL, if one is specified, or fall back to the edX contact us support page. """ - contact_url = 'http://{site_name}/support/contact_us'.format(site_name=SITE_NAME) + contact_url = f'http://{SITE_NAME}/support/contact_us' backend_settings = settings.PROCTORING_BACKENDS if override_email: @@ -322,6 +317,6 @@ def test_correct_edx_support_url(self, status, override_email): # Verify the edX support URL actual_body = self._normalize_whitespace(mail.outbox[0].body) - self.assertIn(' ' - '{contact_url} '.format(contact_url=contact_url), + self.assertIn(f' ' + f'{contact_url} ', actual_body) diff --git a/edx_proctoring/tests/test_mfe_views.py b/edx_proctoring/tests/test_mfe_views.py index a8c369edfa1..d13bacc7daa 100644 --- a/edx_proctoring/tests/test_mfe_views.py +++ b/edx_proctoring/tests/test_mfe_views.py @@ -49,9 +49,7 @@ def setUp(self): 'content_id': self.content_id, 'is_learning_mfe': True, }) - self.expected_exam_url = '{}/course/{}/{}'.format( - settings.LEARNING_MICROFRONTEND_URL, self.course_id, self.content_id - ) + self.expected_exam_url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{self.content_id}' yesterday = timezone.now() - timezone.timedelta(days=1) self.course_scheduled_sections = { BlockUsageLocator.from_string(self.content_id_onboarding): MockScheduleItemData(yesterday), @@ -167,9 +165,7 @@ def test_get_started_timed_exam_attempts_data(self): self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) exam_data = response_data['exam'] - expected_exam_url = '{}/course/{}/{}'.format( - settings.LEARNING_MICROFRONTEND_URL, self.course_id, self.content_id_timed - ) + expected_exam_url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{self.course_id}/{self.content_id_timed}' assert 'prerequisite_status' not in exam_data assert 'active_attempt' in response_data and response_data['active_attempt'] self.assertHasExamData(response_data, has_attempt=True, content_id=self.content_id_timed) @@ -305,8 +301,9 @@ def test_exam_data_contains_link_to_onboarding_exam_if_attempt_in_onboarding_err onboarding_exam = ProctoredExam.objects.get(id=self.onboarding_exam_id) if is_learning_mfe: - expected_exam_url = '{}/course/{}/{}'.format( - settings.LEARNING_MICROFRONTEND_URL, self.course_id, onboarding_exam.content_id + expected_exam_url = ( + f'{settings.LEARNING_MICROFRONTEND_URL}/course/' + f'{self.course_id}/{onboarding_exam.content_id}' ) else: expected_exam_url = reverse('jump_to', args=[self.course_id, onboarding_exam.content_id]) diff --git a/edx_proctoring/tests/test_models.py b/edx_proctoring/tests/test_models.py index ec233666576..2f2d7495a19 100644 --- a/edx_proctoring/tests/test_models.py +++ b/edx_proctoring/tests/test_models.py @@ -397,10 +397,10 @@ def test_get_exam_attempts(self): # create number of exam attempts for i in range(90): - user = User.objects.create(username='tester{0}'.format(i), email='tester{0}@test.com'.format(i)) + user = User.objects.create(username=f'tester{i}', email=f'tester{i}@test.com') ProctoredExamStudentAttempt.create_exam_attempt( proctored_exam.id, user.id, - 'test_attempt_code{0}'.format(i), True, False, 'test_external_id{0}'.format(i) + f'test_attempt_code{i}', True, False, f'test_external_id{i}' ) with self.assertNumQueries(1): @@ -430,10 +430,10 @@ def test_exam_review_policy(self): attempt = ProctoredExamStudentAttempt.create_exam_attempt( proctored_exam.id, self.user.id, - 'test_attempt_code{0}'.format(self.user.id), + f'test_attempt_code{self.user.id}', True, False, - 'test_external_id{0}'.format(self.user.id) + f'test_external_id{self.user.id}' ) attempt.review_policy_id = policy.id attempt.save() diff --git a/edx_proctoring/tests/test_reviews.py b/edx_proctoring/tests/test_reviews.py index 7cf0baa6b17..9be6819c3d0 100644 --- a/edx_proctoring/tests/test_reviews.py +++ b/edx_proctoring/tests/test_reviews.py @@ -224,7 +224,7 @@ def test_post_review_auth(self): ) assert response.status_code == 200 # user in the review group - group_name = '%s_review' % (self.attempt['proctored_exam']['backend']) + group_name = f"{self.attempt['proctored_exam']['backend']}_review" self.user.groups.get_or_create(name=group_name) self.user.is_staff = False self.user.save() diff --git a/edx_proctoring/tests/test_student_view.py b/edx_proctoring/tests/test_student_view.py index d3759875b2d..ca901bfda34 100644 --- a/edx_proctoring/tests/test_student_view.py +++ b/edx_proctoring/tests/test_student_view.py @@ -162,10 +162,10 @@ def test_get_student_view(self): """ rendered_response = self.render_proctored_exam() self.assertIn( - 'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id), + f'data-exam-id="{self.proctored_exam_id}"', rendered_response ) - self.assertIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response) + self.assertIn(self.start_an_exam_msg, rendered_response) # try practice exam variant rendered_response = self.render_practice_exam() @@ -1301,12 +1301,12 @@ def test_get_studentview_unstarted_timed_exam(self): } ) self.assertNotIn( - 'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id), + f'data-exam-id="{self.proctored_exam_id}"', rendered_response ) self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name), rendered_response) self.assertIn('1 hour and 30 minutes', rendered_response) - self.assertNotIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response) + self.assertNotIn(self.start_an_exam_msg, rendered_response) def test_get_studentview_unstarted_timed_exam_with_allowance(self): """ @@ -1329,12 +1329,12 @@ def test_get_studentview_unstarted_timed_exam_with_allowance(self): context={} ) self.assertNotIn( - 'data-exam-id="{proctored_exam_id}"'.format(proctored_exam_id=self.proctored_exam_id), + f'data-exam-id="{self.proctored_exam_id}"', rendered_response ) self.assertIn(self.timed_exam_msg.format(exam_name=self.exam_name), rendered_response) self.assertIn('31 minutes', rendered_response) - self.assertNotIn(self.start_an_exam_msg.format(exam_name=self.exam_name), rendered_response) + self.assertNotIn(self.start_an_exam_msg, rendered_response) @ddt.data( (ProctoredExamStudentAttemptStatus.ready_to_submit, 'Are you sure that you want to submit your timed exam?'), @@ -1550,7 +1550,7 @@ def test_get_student_view_ready_to_resume_status(self, render_exam, exam_type): self.assertIn(self.proctored_exam_ready_to_resume_msg, rendered_response) time_remaining = humanized_time(int(get_exam_attempt_by_id(exam_attempt.id)['time_remaining_seconds'] / 60)) - time_remaining_string = 'You will have {} to complete your exam.'.format(time_remaining) + time_remaining_string = f'You will have {time_remaining} to complete your exam.' self.assertIn(time_remaining_string, rendered_response) @ddt.data( @@ -1578,7 +1578,8 @@ def test_get_student_view_ping_interval_for_view(self, render_exam, exam_type): rendered_response = render_exam(self) - expected_javascript_string = 'edx.courseware.proctored_exam.ProctoringAppPingInterval = {}'.format( - DEFAULT_DESKTOP_APPLICATION_PING_INTERVAL_SECONDS + expected_javascript_string = ( + 'edx.courseware.proctored_exam.ProctoringAppPingInterval = ' + f'{DEFAULT_DESKTOP_APPLICATION_PING_INTERVAL_SECONDS}' ) self.assertIn(expected_javascript_string, rendered_response) diff --git a/edx_proctoring/tests/test_views.py b/edx_proctoring/tests/test_views.py index a03f52540c7..eb5db358b09 100644 --- a/edx_proctoring/tests/test_views.py +++ b/edx_proctoring/tests/test_views.py @@ -93,7 +93,7 @@ def test_no_anonymous_access(self): self.client = Client() # use AnonymousUser on the API calls for urlpattern in urlpatterns: if hasattr(urlpattern, 'name') and 'anonymous.' not in urlpattern.name: - name = 'edx_proctoring:%s' % urlpattern.name + name = f'edx_proctoring:{urlpattern.name}' try: response = self.client.get(reverse(name)) except NoReverseMatch: @@ -295,7 +295,7 @@ def test_update_non_existing_exam(self): response_data = json.loads(response.content.decode('utf-8')) self.assertEqual( response_data['detail'], - 'Attempted to update exam_id={exam_id}, but this exam does not exist.'.format(exam_id=exam_id), + f'Attempted to update exam_id={exam_id}, but this exam does not exist.', ) def test_get_exam_by_id(self): @@ -413,9 +413,7 @@ def test_get_exam_by_bad_content_id(self): self.assertEqual(response.status_code, 400) response_data = json.loads(response.content.decode('utf-8')) message = ( - 'Cannot find proctored exam in course_id=c/d/e with content_id={content_id}'.format( - content_id=proctored_exam.content_id, - ) + f'Cannot find proctored exam in course_id=c/d/e with content_id={proctored_exam.content_id}' ) self.assertEqual(response_data['detail'], message) @@ -497,7 +495,7 @@ def test_no_username(self): # Assert that the onboarding status returned is 'submitted' response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -509,7 +507,7 @@ def test_unauthorized(self): """ response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?username={}&course_id={}'.format(self.other_user.username, self.course_id) + + f'?username={self.other_user.username}&course_id={self.course_id}' ) self.assertEqual(response.status_code, 403) response_data = json.loads(response.content.decode('utf-8')) @@ -524,7 +522,7 @@ def test_staff_authorization(self): self.user.save() response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?username={}&course_id={}'.format(self.other_user.username, self.course_id) + + f'?username={self.other_user.username}&course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) # Should also work for course staff @@ -533,7 +531,7 @@ def test_staff_authorization(self): self.user.save() response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?username={}&course_id={}'.format(self.other_user.username, self.course_id) + + f'?username={self.other_user.username}&course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) @@ -557,7 +555,7 @@ def test_onboarding_mfe_link(self): """ response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}&is_learning_mfe=True'.format(self.course_id) + + f'?course_id={self.course_id}&is_learning_mfe=True' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -572,7 +570,7 @@ def test_no_exam_attempts(self): """ response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -591,7 +589,7 @@ def test_no_verified_attempts(self): update_attempt_status(attempt_id, ProctoredExamStudentAttemptStatus.submitted) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -604,7 +602,7 @@ def test_no_verified_attempts(self): create_exam_attempt(self.onboarding_exam_id, self.user_id, True) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -623,7 +621,7 @@ def test_get_verified_attempt(self): update_attempt_status(attempt_id, ProctoredExamStudentAttemptStatus.verified) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -636,7 +634,7 @@ def test_get_verified_attempt(self): create_exam_attempt(self.onboarding_exam_id, self.user_id, True) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -675,7 +673,7 @@ def test_verified_in_another_course(self): ) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -713,7 +711,7 @@ def test_verified_in_multiple_courses(self): ) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -761,7 +759,7 @@ def test_ignore_history_table(self): update_attempt_status(attempt_id, ProctoredExamStudentAttemptStatus.verified) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -773,7 +771,7 @@ def test_ignore_history_table(self): # Assert that the status has been cleared and is no longer verified response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -793,7 +791,7 @@ def test_ineligible_for_onboarding_exam(self): with mock_perm('edx_proctoring.can_take_proctored_exam'): response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 404) response_data = json.loads(response.content.decode('utf-8')) @@ -836,7 +834,7 @@ def test_multiple_hidden_onboarding_exams(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -856,7 +854,7 @@ def test_no_accessible_onboarding(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 404) response_data = json.loads(response.content.decode('utf-8')) @@ -874,7 +872,7 @@ def test_no_accessible_onboarding_no_schedule(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 404) response_data = json.loads(response.content.decode('utf-8')) @@ -898,7 +896,7 @@ def test_onboarding_not_yet_released(self, due_date): response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -924,7 +922,7 @@ def test_onboarding_past_due(self): response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -968,7 +966,7 @@ def test_multiple_onboarding_exams_all_past_due(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -1005,7 +1003,7 @@ def test_multiple_onboarding_exams_all_to_be_released(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -1059,7 +1057,7 @@ def test_multiple_onboarding_exams_mixed_favor_currently_available(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -1101,7 +1099,7 @@ def test_onboarding_with_api_endpoint(self, api_status, attempt_status, mocked_o response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) mocked_onboarding_api.assert_called_with( @@ -1131,7 +1129,7 @@ def test_onboarding_with_differing_data(self, mocked_onboarding_api, mocked_swit response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) mocked_onboarding_api.assert_called_with( @@ -1156,7 +1154,7 @@ def test_onboarding_with_api_404(self, mocked_onboarding_api, mocked_switch_is_a response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) self.assertEqual(response.status_code, 404) @@ -1173,7 +1171,7 @@ def test_onboarding_with_api_failure(self, mocked_onboarding_api, mocked_switch_ response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.onboarding_exam.course_id) + + f'?course_id={self.onboarding_exam.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -1213,7 +1211,7 @@ def test_multiple_onboarding_exams_mixed_favor_to_be_released(self): )) response = self.client.get( reverse('edx_proctoring:user_onboarding.status') - + '?course_id={}'.format(self.course_id) + + f'?course_id={self.course_id}' ) self.assertEqual(response.status_code, 200) response_data = json.loads(response.content.decode('utf-8')) @@ -1359,8 +1357,8 @@ def test_basic_pagination(self): ) self.assertEqual(response_data['count'], 3) - self.assertEqual(response_data['previous'], base_url + '?page={}'.format(1)) - self.assertEqual(response_data['next'], base_url + '?page={}'.format(3)) + self.assertEqual(response_data['previous'], base_url + '?page=1') + self.assertEqual(response_data['next'], base_url + '?page=3') self.assertEqual(response_data['num_pages'], 3) @patch('edx_proctoring.views.ATTEMPTS_PER_PAGE', 1) @@ -1390,7 +1388,7 @@ def test_pagination_maintains_query_params(self): previous_url = response_data['previous'] next_url = response_data['next'] text_search_string = 'text_search=test.com' - status_filters_string = 'statuses={}'.format(InstructorDashboardOnboardingAttemptStatus.setup_started) + status_filters_string = f'statuses={InstructorDashboardOnboardingAttemptStatus.setup_started}' self.assertIn(base_url, previous_url) self.assertIn('page=1', previous_url) @@ -3139,7 +3137,7 @@ def test_get_exam_attempts(self): self.assertEqual(attempt['proctored_exam']['id'], proctored_exam.id) self.assertEqual(attempt['user']['id'], self.user.id) - url = '{url}?page={invalid_page_no}'.format(url=url, invalid_page_no=9999) + url = f'{url}?page=9999' # url with the invalid page # still gives us the first page result. response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -3337,10 +3335,10 @@ def test_paginated_exam_attempts(self): # create number of exam attempts for i in range(90): - user = User.objects.create(username='student{0}'.format(i), email='student{0}@test.com'.format(i)) + user = User.objects.create(username=f'student{i}', email=f'student{i}@test.com') ProctoredExamStudentAttempt.create_exam_attempt( proctored_exam.id, user.id, - 'test_attempt_code{0}'.format(i), True, False, 'test_external_id{0}'.format(i) + f'test_attempt_code{i}', True, False, f'test_external_id{i}' ) self.client.login_user(self.user) @@ -5494,7 +5492,7 @@ def test_launch_for_course(self): is_proctored=True, ) - expected_url = '/instructor/%s/' % self.course_id + expected_url = f'/instructor/{self.course_id}/' response = self.client.get( reverse('edx_proctoring:instructor_dashboard_course', kwargs={'course_id': self.course_id}) @@ -5513,15 +5511,15 @@ def test_launch_for_exam(self): ) exam_id = proctored_exam.id - expected_url = '/instructor/%s/?exam=%s' % (self.course_id, proctored_exam.external_id) + expected_url = f'/instructor/{self.course_id}/?exam={proctored_exam.external_id}' dashboard_url = reverse('edx_proctoring:instructor_dashboard_exam', kwargs={'course_id': self.course_id, 'exam_id': exam_id}) response = self.client.get(dashboard_url) self.assertRedirects(response, expected_url, fetch_redirect_response=False) # try with an attempt attempt_frag = 'attempt=abcde' - expected_url += '&%s' % attempt_frag - dashboard_url += '?%s' % attempt_frag + expected_url += f'&{attempt_frag}' + dashboard_url += f'?{attempt_frag}' response = self.client.get(dashboard_url) self.assertRedirects(response, expected_url, fetch_redirect_response=False) @@ -5607,7 +5605,7 @@ def test_launch_for_configuration_dashboard(self): ) exam_id = proctored_exam.id - expected_url = '/instructor/%s/?exam=%s&config=true' % (self.course_id, proctored_exam.external_id) + expected_url = f'/instructor/{self.course_id}/?exam={proctored_exam.external_id}&config=true' dashboard_url = reverse('edx_proctoring:instructor_dashboard_exam', kwargs={'course_id': self.course_id, 'exam_id': exam_id}) response = self.client.get(dashboard_url, {'config': 'true'}) @@ -5642,7 +5640,7 @@ def test_multiple_exams_returns_correct_dashboard(self, exam_1_is_proctored, exa backend='test', ) - expected_url = '/instructor/%s/' % self.course_id + expected_url = f'/instructor/{self.course_id}/' response = self.client.get( reverse('edx_proctoring:instructor_dashboard_course', kwargs={'course_id': self.course_id}) @@ -5650,7 +5648,7 @@ def test_multiple_exams_returns_correct_dashboard(self, exam_1_is_proctored, exa if not exam_1_is_proctored and not exam_2_is_proctored: self.assertEqual(response.status_code, 404) self.assertEqual( - 'No proctored exams in course {}'.format(self.course_id), + f'No proctored exams in course {self.course_id}', response.data ) else: @@ -5681,7 +5679,7 @@ def test_can_delete_user(self): for i, backend in enumerate(('test', 'null', 'test', None)): proctored_exam = ProctoredExam.objects.create( course_id='a/b/c', - content_id='test_content%s' % i, + content_id=f'test_content{i}', exam_name='Test Exam', external_id='123aXqe3', is_proctored=True, diff --git a/edx_proctoring/tests/test_workerconfig.py b/edx_proctoring/tests/test_workerconfig.py index 50a306a790d..836089a135f 100644 --- a/edx_proctoring/tests/test_workerconfig.py +++ b/edx_proctoring/tests/test_workerconfig.py @@ -19,7 +19,7 @@ class TestWorkerConfig(unittest.TestCase): def setUp(self): # pylint: disable=super-method-not-called super().setUp() - self.outfile = tempfile.mktemp(prefix='test-%d' % os.getpid()) + self.outfile = tempfile.mktemp(prefix=f'test-{os.getpid()}') self.to_del = [self.outfile] def tearDown(self): # pylint: disable=super-method-not-called diff --git a/edx_proctoring/tests/utils.py b/edx_proctoring/tests/utils.py index 53a8ada5b4a..47f4ad0c1a2 100644 --- a/edx_proctoring/tests/utils.py +++ b/edx_proctoring/tests/utils.py @@ -86,7 +86,7 @@ def create_batch_users(self, batch_size): for i in range(batch_size): created_user = User( username='student' + str(i), - email='student{}@test.com'.format(i), + email=f'student{i}@test.com', ) created_user.save() users_list.append(created_user)