diff --git a/lms/djangoapps/mobile_api/course_info/tests.py b/lms/djangoapps/mobile_api/course_info/tests.py index 40a0a3ed28..490f530299 100644 --- a/lms/djangoapps/mobile_api/course_info/tests.py +++ b/lms/djangoapps/mobile_api/course_info/tests.py @@ -185,7 +185,7 @@ class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTes # but shouldn't finish with any response = self.api_response(api_version=api_version) - assert '/courses/{}/jump_to_id/'.format(self.course.id) in response.data['handouts_html'] + assert f'/courses/{self.course.id}/jump_to_id/' in response.data['handouts_html'] @ddt.data( (ModuleStoreEnum.Type.mongo, API_V05), @@ -206,7 +206,7 @@ class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTes # but shouldn't finish with any response = self.api_response(api_version=api_version) - assert '/courses/{}/'.format(self.course.id) in response.data['handouts_html'] + assert f'/courses/{self.course.id}/' in response.data['handouts_html'] def add_mobile_available_toy_course(self): """ use toy course with handouts, and make it mobile_available """ diff --git a/lms/djangoapps/mobile_api/users/tests.py b/lms/djangoapps/mobile_api/users/tests.py index 4f3a0d7f4f..97b7608c2f 100644 --- a/lms/djangoapps/mobile_api/users/tests.py +++ b/lms/djangoapps/mobile_api/users/tests.py @@ -126,9 +126,9 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest assert len(courses) == 1 found_course = courses[0]['course'] - assert 'courses/{}/about'.format(self.course.id) in found_course['course_about'] - assert 'course_info/{}/updates'.format(self.course.id) in found_course['course_updates'] - assert 'course_info/{}/handouts'.format(self.course.id) in found_course['course_handouts'] + assert f'courses/{self.course.id}/about' in found_course['course_about'] + assert f'course_info/{self.course.id}/updates' in found_course['course_updates'] + assert f'course_info/{self.course.id}/handouts' in found_course['course_handouts'] assert found_course['id'] == str(self.course.id) assert courses[0]['mode'] == CourseMode.DEFAULT_MODE_SLUG assert courses[0]['course']['subscription_id'] == self.course.clean_id(padding_char='_') @@ -237,7 +237,7 @@ class TestUserEnrollmentApi(UrlResetMixin, MobileAPITestCase, MobileAuthUserTest response = self.api_response(api_version=api_version) response_discussion_url = response.data[0]['course']['discussion_url'] - assert '/api/discussion/v1/courses/{}'.format(self.course.id) in response_discussion_url + assert f'/api/discussion/v1/courses/{self.course.id}' in response_discussion_url @ddt.data(API_V05, API_V1) def test_org_query(self, api_version): diff --git a/lms/djangoapps/monitoring/scripts/generate_code_owner_mappings.py b/lms/djangoapps/monitoring/scripts/generate_code_owner_mappings.py index 2a284e5db6..9d5ce01f82 100644 --- a/lms/djangoapps/monitoring/scripts/generate_code_owner_mappings.py +++ b/lms/djangoapps/monitoring/scripts/generate_code_owner_mappings.py @@ -111,7 +111,7 @@ def main(repo_csv, app_csv, dep_csv): # NB: An automated script looks for this comment when updating config files, # so please update regenerate_code_owners_config.py in jenkins-job-dsl-internal # if you change the comment format here. - print('# Do not hand edit CODE_OWNER_MAPPINGS. Generated by {}'.format(os.path.basename(__file__))) + print(f'# Do not hand edit CODE_OWNER_MAPPINGS. Generated by {os.path.basename(__file__)}') print('CODE_OWNER_MAPPINGS:') for owner, path_list in sorted(owner_to_paths_map.items()): print(f" {owner}:") @@ -120,7 +120,7 @@ def main(repo_csv, app_csv, dep_csv): print(f" - {path}") owner_with_mappings_set = set(owner_to_paths_map.keys()) - print('# Do not hand edit CODE_OWNER_THEMES. Generated by {}'.format(os.path.basename(__file__))) + print(f'# Do not hand edit CODE_OWNER_THEMES. Generated by {os.path.basename(__file__)}') print('CODE_OWNER_THEMES:') for theme, owner_list in sorted(owner_map['theme_to_owners_map'].items()): theme_owner_set = set(owner_list) diff --git a/lms/djangoapps/program_enrollments/api/tests/test_linking.py b/lms/djangoapps/program_enrollments/api/tests/test_linking.py index a3f3d34d98..8c74fa9a51 100644 --- a/lms/djangoapps/program_enrollments/api/tests/test_linking.py +++ b/lms/djangoapps/program_enrollments/api/tests/test_linking.py @@ -121,7 +121,7 @@ class TestLinkProgramEnrollmentsMixin: program_course_enrollment.course_enrollment for program_course_enrollment in program_course_enrollments ] - assert all((course_enrollment.is_active for course_enrollment in course_enrollments)) + assert all(course_enrollment.is_active for course_enrollment in course_enrollments) self.assertCountEqual( course_keys, [course_enrollment.course.id for course_enrollment in course_enrollments] diff --git a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py index 09baa4f7ff..b616c6f9c9 100644 --- a/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py +++ b/lms/djangoapps/program_enrollments/rest_api/v1/tests/test_views.py @@ -2096,7 +2096,7 @@ class ProgramCourseEnrollmentOverviewGetTests( def test_course_run_url(self): self.log_in() - course_run_url = 'http://testserver/courses/{}/course/'.format(str(self.course_id)) + course_run_url = f'http://testserver/courses/{str(self.course_id)}/course/' response_status_code, response_course_runs = self.get_status_and_course_runs() assert status.HTTP_200_OK == response_status_code @@ -2130,7 +2130,7 @@ class ProgramCourseEnrollmentOverviewGetTests( course_run_overview = response_course_runs[0] assert course_run_overview['course_run_id'] == str(self.course_id) - assert course_run_overview['display_name'] == '{} Course'.format(str(self.course_id)) + assert course_run_overview['display_name'] == f'{str(self.course_id)} Course' def test_emails_enabled(self): self.log_in() diff --git a/lms/djangoapps/support/views/enrollments.py b/lms/djangoapps/support/views/enrollments.py index 92b9e58594..ff314e4b84 100644 --- a/lms/djangoapps/support/views/enrollments.py +++ b/lms/djangoapps/support/views/enrollments.py @@ -99,7 +99,7 @@ class EnrollmentSupportListView(GenericAPIView): old_mode=old_mode )) except KeyError as err: - return HttpResponseBadRequest('The field {} is required.'.format(str(err))) + return HttpResponseBadRequest(f'The field {str(err)} is required.') except InvalidKeyError: return HttpResponseBadRequest('Could not parse course key.') except (CourseEnrollment.DoesNotExist, User.DoesNotExist): diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index b306e1d1f2..42d5d651ae 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -2951,7 +2951,7 @@ class TestBulkMembershipManagement(TeamAPITestCase): team1 = 'team wind power' team2 = 'team 2' for name_enum in enumerate(['a', 'b', 'c', 'd', 'e', 'f', 'g']): - username = 'user_{}'.format(name_enum[1]) + username = f'user_{name_enum[1]}' self.create_and_enroll_student(username=username, mode=CourseMode.MASTERS) csv_content += f'{username},masters,{team1},{team2}' + '\n' @@ -2964,7 +2964,7 @@ class TestBulkMembershipManagement(TeamAPITestCase): data={'csv': csv_file}, user='staff' ) response_text = json.loads(response.content.decode('utf-8')) - assert response_text['errors'][0] == 'New membership for team {} would exceed max size of {}.'.format(team1, 3) + assert response_text['errors'][0] == f'New membership for team {team1} would exceed max size of {3}.' def test_deletion_via_upload_csv(self): # create a team membership that will be used further down diff --git a/lms/djangoapps/verify_student/management/commands/manual_verifications.py b/lms/djangoapps/verify_student/management/commands/manual_verifications.py index 603d654a24..3dcdf98ad8 100644 --- a/lms/djangoapps/verify_student/management/commands/manual_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/manual_verifications.py @@ -63,7 +63,7 @@ class Command(BaseCommand): len(failed_emails), total_emails )) - log.error('Failed emails:{}'.format(pformat(failed_emails))) + log.error(f'Failed emails:{pformat(failed_emails)}') else: log.info(f'Successfully generated manual verification for {total_emails} emails.') diff --git a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py index 79c1912f6e..d7311a5b45 100644 --- a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py @@ -69,7 +69,7 @@ class Command(BaseCommand): attempts_to_retry = SoftwareSecurePhotoVerification.objects.filter(status='must_retry') force_must_retry = False - log.info("Attempting to retry {} failed PhotoVerification submissions".format(len(attempts_to_retry))) + log.info(f"Attempting to retry {len(attempts_to_retry)} failed PhotoVerification submissions") for index, attempt in enumerate(attempts_to_retry): log.info(f"Retrying submission #{index} (ID: {attempt.id}, User: {attempt.user})") diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_manual_verify_student.py b/lms/djangoapps/verify_student/management/commands/tests/test_manual_verify_student.py index b6dd092267..578573d53a 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_manual_verify_student.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_manual_verify_student.py @@ -114,4 +114,4 @@ class TestVerifyStudentCommand(TestCase): Verify command raises the CommandError for invalid file path. """ with pytest.raises(CommandError): - call_command('manual_verifications', '--email-ids-file', u'invalid/email_id/file/path') + call_command('manual_verifications', '--email-ids-file', 'invalid/email_id/file/path') diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py b/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py index 8a821b775d..c4cde9f649 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_send_verification_expiry_email.py @@ -294,7 +294,7 @@ class TestSendVerificationExpiryEmail(MockS3BotoMixin, TestCase): call_command('send_verification_expiry_email') logger.check_present( - (LOGGER_NAME, 'ERROR', 'Could not send email for verification id {}'.format(verifications[0].id)), + (LOGGER_NAME, 'ERROR', f'Could not send email for verification id {verifications[0].id}'), ) for verification in verifications: diff --git a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py index 05a26cac65..bf7ab735ec 100644 --- a/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py +++ b/lms/djangoapps/verify_student/management/commands/tests/test_verify_student.py @@ -77,7 +77,7 @@ class TestVerifyStudentCommand(MockS3BotoMixin, TestVerificationBase): log.check_present( ( LOGGER_NAME, 'INFO', - 'Attempting to retry {} failed PhotoVerification submissions'.format(1) + f'Attempting to retry {1} failed PhotoVerification submissions' ), ) diff --git a/lms/djangoapps/verify_student/services.py b/lms/djangoapps/verify_student/services.py index 711c75368b..768162f587 100644 --- a/lms/djangoapps/verify_student/services.py +++ b/lms/djangoapps/verify_student/services.py @@ -238,5 +238,5 @@ class IDVerificationService: """ location = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification' if course_id: - location += '?course_id={}'.format(quote(str(course_id))) + location += f'?course_id={quote(str(course_id))}' return location diff --git a/lms/djangoapps/verify_student/ssencrypt.py b/lms/djangoapps/verify_student/ssencrypt.py index 47bc243e9c..1d4ddea169 100644 --- a/lms/djangoapps/verify_student/ssencrypt.py +++ b/lms/djangoapps/verify_student/ssencrypt.py @@ -24,7 +24,6 @@ import logging import os from hashlib import md5, sha256 -import six from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.padding import MGF1, OAEP @@ -93,8 +92,8 @@ def random_aes_key(): def pad(data): """ Pad the given `data` such that it fits into the proper AES block size """ - if six.PY3 and not isinstance(data, (bytes, bytearray)): - data = six.b(data) + if not isinstance(data, (bytes, bytearray)): + data = data.encode() padder = PKCS7(AES.block_size).padder() return padder.update(data) + padder.finalize() @@ -185,7 +184,7 @@ def signing_format_message(method, headers_dict, body_dict): will return a str that represents the normalized version of this messsage that will be used to generate a signature. """ - headers_str = "{}\n\n{}".format(method, header_string(headers_dict)) + headers_str = f"{method}\n\n{header_string(headers_dict)}" body_str = body_string(body_dict) message = headers_str + body_str diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index fc1ab4ce00..883aef9e61 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -115,7 +115,7 @@ class StartView(TestCase): """ def start_url(self, course_id=""): - return "/verify_student/{}".format(urllib.parse.quote(course_id)) + return f"/verify_student/{urllib.parse.quote(course_id)}" def test_start_new_verification(self): """