refactor: pyupgrade second iteration (#27442)
This commit is contained in:
@@ -142,7 +142,7 @@ class CcxListTest(CcxRestApiTest):
|
||||
self.list_url = reverse('ccx_api:v0:ccx:list')
|
||||
self.list_url_master_course = urllib.parse.urljoin(
|
||||
self.list_url,
|
||||
'?master_course_id={}'.format(urllib.parse.quote_plus(self.master_course_key_str))
|
||||
f'?master_course_id={urllib.parse.quote_plus(self.master_course_key_str)}'
|
||||
)
|
||||
|
||||
def test_authorization(self):
|
||||
@@ -363,7 +363,7 @@ class CcxListTest(CcxRestApiTest):
|
||||
assert resp.data['previous'] is not None
|
||||
|
||||
# last page + 1
|
||||
url = '{}&page={}'.format(self.list_url_master_course, num_pages + 1)
|
||||
url = f'{self.list_url_master_course}&page={num_pages + 1}'
|
||||
resp = self.client.get(url, {}, HTTP_AUTHORIZATION=self.auth)
|
||||
assert resp.status_code == status.HTTP_404_NOT_FOUND
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class Command(BaseCommand):
|
||||
try:
|
||||
user = User.objects.get(id=user_id)
|
||||
except User.DoesNotExist:
|
||||
log.warning('User {user} could not be found'.format(user=user_id))
|
||||
log.warning(f'User {user_id} could not be found')
|
||||
if user is not None:
|
||||
log.info(
|
||||
'Calling generate_certificate_task for {user} : {course}'.format(
|
||||
|
||||
@@ -25,7 +25,7 @@ def get_user_from_identifier(identifier):
|
||||
"""
|
||||
user = User.objects.filter(Q(username=identifier) | Q(email=identifier)).first()
|
||||
if not user:
|
||||
raise CommandError("User {} does not exist.".format(identifier))
|
||||
raise CommandError(f"User {identifier} does not exist.")
|
||||
return user
|
||||
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ class RegenerateCertificatesTest(CertificateManagementTest):
|
||||
self.course.issue_badges = issue_badges
|
||||
self.store.update_item(self.course, None)
|
||||
|
||||
args = '-u {} -c {}'.format(self.user.email, str(key))
|
||||
args = f'-u {self.user.email} -c {str(key)}'
|
||||
call_command(self.command, *args.split(' '))
|
||||
|
||||
assert xqueue.return_value.regen_cert.call_args.args == (
|
||||
@@ -210,7 +210,7 @@ class RegenerateCertificatesTest(CertificateManagementTest):
|
||||
key = self.course.location.course_key
|
||||
self._create_cert(key, self.user, CertificateStatuses.downloadable)
|
||||
|
||||
args = '-u {} -c {} --insecure'.format(self.user.email, str(key))
|
||||
args = f'-u {self.user.email} -c {str(key)} --insecure'
|
||||
call_command(self.command, *args.split(' '))
|
||||
|
||||
certificate = GeneratedCertificate.eligible_certificates.get(
|
||||
@@ -247,7 +247,7 @@ class UngenerateCertificatesTest(CertificateManagementTest):
|
||||
self._create_cert(key, self.user, CertificateStatuses.unavailable)
|
||||
|
||||
with mock_passing_grade():
|
||||
args = '-c {} --insecure'.format(str(key))
|
||||
args = f'-c {str(key)} --insecure'
|
||||
call_command(self.command, *args.split(' '))
|
||||
|
||||
assert mock_send_to_queue.called
|
||||
|
||||
@@ -1261,7 +1261,7 @@ class CertificateGenerationCommandConfiguration(ConfigurationModel):
|
||||
.. no_pii:
|
||||
"""
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
app_label = "certificates"
|
||||
verbose_name = "cert_generation argument"
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class Command(BaseCommand):
|
||||
"""
|
||||
|
||||
self.stdout.write(
|
||||
'\tFetching Enrollments from {start} to {end}'.format(start=offset, end=offset + batch_size)
|
||||
f'\tFetching Enrollments from {offset} to {offset + batch_size}'
|
||||
)
|
||||
enrollments = enrollments_queryset.select_related(
|
||||
'enterprise_customer_user', 'enterprise_customer_user__enterprise_customer'
|
||||
@@ -133,7 +133,7 @@ class Command(BaseCommand):
|
||||
invalid = 0
|
||||
|
||||
self.stdout.write(
|
||||
'\t\tProcessing Total : {},'.format(len(enrollments_batch))
|
||||
f'\t\tProcessing Total : {len(enrollments_batch)},'
|
||||
)
|
||||
|
||||
for enrollment in enrollments_batch:
|
||||
@@ -167,7 +167,7 @@ class Command(BaseCommand):
|
||||
continue
|
||||
enrollments_payload.append(enrollment_payload)
|
||||
|
||||
self.stdout.write('\t\tFound {count} Paid enrollments to sync'.format(count=len(enrollments_payload)))
|
||||
self.stdout.write(f'\t\tFound {len(enrollments_payload)} Paid enrollments to sync')
|
||||
if not enrollments_payload:
|
||||
return 0, 0, 0, invalid, non_paid, []
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class BlockListGetForm(Form):
|
||||
try:
|
||||
usage_key = UsageKey.from_string(usage_key)
|
||||
except InvalidKeyError:
|
||||
raise ValidationError("'{}' is not a valid usage key.".format(str(usage_key))) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
raise ValidationError(f"'{str(usage_key)}' is not a valid usage key.") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
return usage_key.replace(course_key=modulestore().fill_in_run(usage_key.course_key))
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView):
|
||||
patch_response_headers(response)
|
||||
return response
|
||||
except ItemNotFoundError as exception:
|
||||
raise Http404("Block not found: {}".format(str(exception))) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
raise Http404(f"Block not found: {str(exception)}") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
|
||||
@view_auth_classes(is_authenticated=False)
|
||||
@@ -305,7 +305,7 @@ class BlocksInCourseView(BlocksView):
|
||||
course_key = CourseKey.from_string(course_key_string)
|
||||
course_usage_key = modulestore().make_course_usage_key(course_key)
|
||||
except InvalidKeyError:
|
||||
raise ValidationError("'{}' is not a valid course key.".format(str(course_key_string))) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
raise ValidationError(f"'{str(course_key_string)}' is not a valid course key.") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
response = super().list(request, course_usage_key,
|
||||
hide_access_denials=hide_access_denials)
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class CourseDetailGetForm(UsernameValidatorMixin, Form):
|
||||
try:
|
||||
return CourseKey.from_string(course_key_string)
|
||||
except InvalidKeyError:
|
||||
raise ValidationError("'{}' is not a valid course key.".format(str(course_key_string))) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
raise ValidationError(f"'{str(course_key_string)}' is not a valid course key.") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
|
||||
class CourseListGetForm(UsernameValidatorMixin, Form):
|
||||
|
||||
@@ -187,11 +187,11 @@ class TestGetCourseListMultipleCourses(CourseListTestMixin, ModuleStoreTestCase)
|
||||
# No filtering.
|
||||
unfiltered_courses = self._make_api_call(self.staff_user, self.staff_user)
|
||||
for org in [self.course.org, alternate_course.org]:
|
||||
assert any(((course.org == org) for course in unfiltered_courses))
|
||||
assert any((course.org == org) for course in unfiltered_courses)
|
||||
|
||||
# With filtering.
|
||||
filtered_courses = self._make_api_call(self.staff_user, self.staff_user, org=self.course.org)
|
||||
assert all(((course.org == self.course.org) for course in filtered_courses))
|
||||
assert all((course.org == self.course.org) for course in filtered_courses)
|
||||
|
||||
def test_filter(self):
|
||||
# Create a second course to be filtered out of queries.
|
||||
|
||||
@@ -177,11 +177,11 @@ class CourseListViewTestCaseMultipleCourses(CourseApiTestViewMixin, ModuleStoreT
|
||||
# No filtering.
|
||||
unfiltered_response = self.verify_response(params={'username': self.staff_user.username})
|
||||
for org in [self.course.org, alternate_course.org]:
|
||||
assert any(((course['org'] == org) for course in unfiltered_response.data['results']))
|
||||
assert any((course['org'] == org) for course in unfiltered_response.data['results'])
|
||||
|
||||
# With filtering.
|
||||
filtered_response = self.verify_response(params={'org': self.course.org, 'username': self.staff_user.username})
|
||||
assert all(((course['org'] == self.course.org) for course in filtered_response.data['results']))
|
||||
assert all((course['org'] == self.course.org) for course in filtered_response.data['results'])
|
||||
|
||||
def test_filter(self):
|
||||
self.setup_user(self.staff_user)
|
||||
|
||||
@@ -45,7 +45,7 @@ class TestCourseGoalsAPI(EventTrackingTestCase, SharedModuleStoreTestCase):
|
||||
def test_add_valid_goal(self, ga_call):
|
||||
""" Ensures a correctly formatted post succeeds."""
|
||||
response = self.post_course_goal(valid=True, goal_key='certify')
|
||||
assert self.get_event((- 1))['name'] == EVENT_NAME_ADDED
|
||||
assert self.get_event(- 1)['name'] == EVENT_NAME_ADDED
|
||||
ga_call.assert_called_with(self.user.id, EVENT_NAME_ADDED)
|
||||
assert response.status_code == 201
|
||||
|
||||
@@ -77,7 +77,7 @@ class TestCourseGoalsAPI(EventTrackingTestCase, SharedModuleStoreTestCase):
|
||||
self.post_course_goal(valid=True, goal_key='explore')
|
||||
self.post_course_goal(valid=True, goal_key='certify')
|
||||
self.post_course_goal(valid=True, goal_key='unsure')
|
||||
assert self.get_event((- 1))['name'] == EVENT_NAME_UPDATED
|
||||
assert self.get_event(- 1)['name'] == EVENT_NAME_UPDATED
|
||||
|
||||
ga_call.assert_called_with(self.user.id, EVENT_NAME_UPDATED)
|
||||
current_goals = CourseGoal.objects.filter(user=self.user, course_key=self.course.id)
|
||||
|
||||
@@ -37,7 +37,7 @@ class DatesTabTestViews(BaseCourseHomeTests):
|
||||
# Pulling out the date blocks to check learner has access.
|
||||
date_blocks = response.data.get('course_date_blocks')
|
||||
assert response.data.get('learner_is_full_access') == (enrollment_mode == CourseMode.VERIFIED)
|
||||
assert all((block.get('learner_has_access') for block in date_blocks))
|
||||
assert all(block.get('learner_has_access') for block in date_blocks)
|
||||
|
||||
@override_experiment_waffle_flag(COURSE_HOME_MICROFRONTEND, active=True)
|
||||
@override_waffle_flag(COURSE_HOME_MICROFRONTEND_DATES_TAB, active=True)
|
||||
|
||||
@@ -68,8 +68,8 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
dates_widget = response.data.get('dates_widget')
|
||||
assert dates_widget
|
||||
date_blocks = dates_widget.get('course_date_blocks')
|
||||
assert all(((block.get('title') != '') for block in date_blocks))
|
||||
assert all((block.get('date') for block in date_blocks))
|
||||
assert all((block.get('title') != '') for block in date_blocks)
|
||||
assert all(block.get('date') for block in date_blocks)
|
||||
|
||||
resume_course = response.data.get('resume_course')
|
||||
resume_course_url = resume_course.get('url')
|
||||
@@ -91,8 +91,8 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
dates_widget = response.data.get('dates_widget')
|
||||
assert dates_widget
|
||||
date_blocks = dates_widget.get('course_date_blocks')
|
||||
assert all(((block.get('title') != '') for block in date_blocks))
|
||||
assert all((block.get('date') for block in date_blocks))
|
||||
assert all((block.get('title') != '') for block in date_blocks)
|
||||
assert all(block.get('date') for block in date_blocks)
|
||||
|
||||
@override_experiment_waffle_flag(COURSE_HOME_MICROFRONTEND, active=True)
|
||||
@override_waffle_flag(COURSE_HOME_MICROFRONTEND_OUTLINE_TAB, active=True)
|
||||
@@ -140,7 +140,7 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
|
||||
instructor = UserFactory(
|
||||
username='instructor',
|
||||
email=u'instructor@example.com',
|
||||
email='instructor@example.com',
|
||||
password='foo',
|
||||
is_staff=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user