diff --git a/lms/djangoapps/ccx/api/v0/tests/test_views.py b/lms/djangoapps/ccx/api/v0/tests/test_views.py index e36f20eba4..3b42b1b92d 100644 --- a/lms/djangoapps/ccx/api/v0/tests/test_views.py +++ b/lms/djangoapps/ccx/api/v0/tests/test_views.py @@ -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 diff --git a/lms/djangoapps/certificates/management/commands/cert_generation.py b/lms/djangoapps/certificates/management/commands/cert_generation.py index 3b9edf56e4..122e16a675 100644 --- a/lms/djangoapps/certificates/management/commands/cert_generation.py +++ b/lms/djangoapps/certificates/management/commands/cert_generation.py @@ -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( diff --git a/lms/djangoapps/certificates/management/commands/cert_whitelist.py b/lms/djangoapps/certificates/management/commands/cert_whitelist.py index 0876166767..1c9515457b 100644 --- a/lms/djangoapps/certificates/management/commands/cert_whitelist.py +++ b/lms/djangoapps/certificates/management/commands/cert_whitelist.py @@ -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 diff --git a/lms/djangoapps/certificates/management/commands/tests/test_cert_management.py b/lms/djangoapps/certificates/management/commands/tests/test_cert_management.py index 381517aa22..fee1b3ea3b 100644 --- a/lms/djangoapps/certificates/management/commands/tests/test_cert_management.py +++ b/lms/djangoapps/certificates/management/commands/tests/test_cert_management.py @@ -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 diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 3028a22449..0f448e027b 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -1261,7 +1261,7 @@ class CertificateGenerationCommandConfiguration(ConfigurationModel): .. no_pii: """ - class Meta(object): + class Meta: app_label = "certificates" verbose_name = "cert_generation argument" diff --git a/lms/djangoapps/commerce/management/commands/create_orders_for_old_enterprise_course_enrollment.py b/lms/djangoapps/commerce/management/commands/create_orders_for_old_enterprise_course_enrollment.py index e2d1e021f1..beeb96cd80 100644 --- a/lms/djangoapps/commerce/management/commands/create_orders_for_old_enterprise_course_enrollment.py +++ b/lms/djangoapps/commerce/management/commands/create_orders_for_old_enterprise_course_enrollment.py @@ -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, [] diff --git a/lms/djangoapps/course_api/blocks/forms.py b/lms/djangoapps/course_api/blocks/forms.py index 24c6476c25..94bc9fa38d 100644 --- a/lms/djangoapps/course_api/blocks/forms.py +++ b/lms/djangoapps/course_api/blocks/forms.py @@ -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)) diff --git a/lms/djangoapps/course_api/blocks/views.py b/lms/djangoapps/course_api/blocks/views.py index 28578269f3..6aa480218d 100644 --- a/lms/djangoapps/course_api/blocks/views.py +++ b/lms/djangoapps/course_api/blocks/views.py @@ -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) diff --git a/lms/djangoapps/course_api/forms.py b/lms/djangoapps/course_api/forms.py index f9843f63c0..4e7afc5978 100644 --- a/lms/djangoapps/course_api/forms.py +++ b/lms/djangoapps/course_api/forms.py @@ -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): diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index 4c01099095..b0af5bb37d 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -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. diff --git a/lms/djangoapps/course_api/tests/test_views.py b/lms/djangoapps/course_api/tests/test_views.py index 6b8a1a7737..5f0a28ad27 100644 --- a/lms/djangoapps/course_api/tests/test_views.py +++ b/lms/djangoapps/course_api/tests/test_views.py @@ -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) diff --git a/lms/djangoapps/course_goals/tests/test_api.py b/lms/djangoapps/course_goals/tests/test_api.py index cf25849680..00d4c4801a 100644 --- a/lms/djangoapps/course_goals/tests/test_api.py +++ b/lms/djangoapps/course_goals/tests/test_api.py @@ -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) diff --git a/lms/djangoapps/course_home_api/dates/v1/tests/test_views.py b/lms/djangoapps/course_home_api/dates/v1/tests/test_views.py index 0824b570cd..d867e60ed5 100644 --- a/lms/djangoapps/course_home_api/dates/v1/tests/test_views.py +++ b/lms/djangoapps/course_home_api/dates/v1/tests/test_views.py @@ -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) diff --git a/lms/djangoapps/course_home_api/outline/v1/tests/test_views.py b/lms/djangoapps/course_home_api/outline/v1/tests/test_views.py index ad4eb9564a..81fe9b93bc 100644 --- a/lms/djangoapps/course_home_api/outline/v1/tests/test_views.py +++ b/lms/djangoapps/course_home_api/outline/v1/tests/test_views.py @@ -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 )