refactor: pyupgrade second iteration
This commit is contained in:
@@ -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 """
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.')
|
||||
|
||||
|
||||
@@ -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})")
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user