diff --git a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py index b9885a85ca..bf242f08bf 100644 --- a/openedx/core/djangoapps/credentials/tasks/v1/tasks.py +++ b/openedx/core/djangoapps/credentials/tasks/v1/tasks.py @@ -325,7 +325,7 @@ def send_grade_if_interesting(user, course_run_key, mode, status, letter_grade, if not is_course_run_in_a_program(course_run_key): if verbose: logger.info( - "Skipping send grade: course run not in a program. [{course_id}]".format(course_id=str(course_run_key)) + f"Skipping send grade: course run not in a program. [{str(course_run_key)}]" ) return diff --git a/openedx/core/djangoapps/credit/signature.py b/openedx/core/djangoapps/credit/signature.py index 93cba3792e..a631e078a7 100644 --- a/openedx/core/djangoapps/credit/signature.py +++ b/openedx/core/djangoapps/credit/signature.py @@ -78,7 +78,7 @@ def signature(params, shared_secret): """ encoded_params = "".join([ - "{key}:{value}".format(key=key, value=params[key]) + f"{key}:{params[key]}" for key in sorted(params.keys()) if key != "signature" ]) diff --git a/openedx/core/djangoapps/credit/tests/test_api.py b/openedx/core/djangoapps/credit/tests/test_api.py index 47d5ddc3ef..f9c096c53d 100644 --- a/openedx/core/djangoapps/credit/tests/test_api.py +++ b/openedx/core/djangoapps/credit/tests/test_api.py @@ -198,7 +198,7 @@ class CreditApiTestBase(ModuleStoreTestCase): """ Mock GET requests to the ecommerce course API endpoint. """ httpretty.reset() httpretty.register_uri( - httpretty.GET, '{}/courses/{}/?include_products=1'.format(TEST_API_URL, str(course_key)), + httpretty.GET, f'{TEST_API_URL}/courses/{str(course_key)}/?include_products=1', status=status, body=json.dumps(body), content_type='application/json', ) diff --git a/openedx/core/djangoapps/credit/tests/test_views.py b/openedx/core/djangoapps/credit/tests/test_views.py index 57e752c3d4..90f2a30a27 100644 --- a/openedx/core/djangoapps/credit/tests/test_views.py +++ b/openedx/core/djangoapps/credit/tests/test_views.py @@ -686,7 +686,7 @@ class CreditEligibilityViewTests(AuthMixin, UserMixin, ReadOnlyMixin, TestCase): def test_get_with_invalid_course_key(self): """ Verify the endpoint returns HTTP status 400 if the provided course_key is not an actual CourseKey. """ - url = '{}?username=edx&course_key=a'.format(reverse(self.view_name)) + url = f'{reverse(self.view_name)}?username=edx&course_key=a' response = self.client.get(url) assert response.status_code == 400 self.assertDictEqual(response.data, {'detail': '[a] is not a valid course key.'}) diff --git a/openedx/core/djangoapps/debug/views.py b/openedx/core/djangoapps/debug/views.py index 3554e938a1..ec1c48155f 100644 --- a/openedx/core/djangoapps/debug/views.py +++ b/openedx/core/djangoapps/debug/views.py @@ -54,4 +54,4 @@ def show_reference_template(request, template): return render_to_response(template, context) except TemplateDoesNotExist: - return HttpResponseNotFound('Missing template {template}'.format(template=bleach.clean(template, strip=True))) + return HttpResponseNotFound(f'Missing template {bleach.clean(template, strip=True)}') diff --git a/openedx/core/djangoapps/django_comment_common/comment_client/models.py b/openedx/core/djangoapps/django_comment_common/comment_client/models.py index ed4a65b6f2..3ca2daa1f1 100644 --- a/openedx/core/djangoapps/django_comment_common/comment_client/models.py +++ b/openedx/core/djangoapps/django_comment_common/comment_client/models.py @@ -89,7 +89,7 @@ class Model: record the class name of the model. """ tags = [ - '{}.{}:{}'.format(self.__class__.__name__, attr, self[attr]) + f'{self.__class__.__name__}.{attr}:{self[attr]}' for attr in self.metric_tag_fields if attr in self.attributes ] @@ -180,7 +180,7 @@ class Model: raise CommentClientRequestError("Must provide base_url when using default url function") if action not in cls.DEFAULT_ACTIONS: # lint-amnesty, pylint: disable=no-else-raise raise ValueError( - "Invalid action {}. The supported action must be in {}".format(action, str(cls.DEFAULT_ACTIONS)) + f"Invalid action {action}. The supported action must be in {str(cls.DEFAULT_ACTIONS)}" ) elif action in cls.DEFAULT_ACTIONS_WITH_ID: try: diff --git a/openedx/core/djangoapps/embargo/models.py b/openedx/core/djangoapps/embargo/models.py index 4ce5dcd1c5..875ecd32e8 100644 --- a/openedx/core/djangoapps/embargo/models.py +++ b/openedx/core/djangoapps/embargo/models.py @@ -70,7 +70,7 @@ class EmbargoedCourse(models.Model): not_em = "Not " if self.embargoed: not_em = "" - return "Course '{}' is {}Embargoed".format(str(self.course_id), not_em) + return f"Course '{str(self.course_id)}' is {not_em}Embargoed" @python_2_unicode_compatible diff --git a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py index 889316b6ea..dafeff76ca 100644 --- a/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py +++ b/openedx/core/djangoapps/oauth_dispatch/management/commands/tests/test_clear_expired_tokens.py @@ -67,12 +67,12 @@ class EdxClearExpiredTokensTests(TestCase): # lint-amnesty, pylint: disable=mis ( LOGGER_NAME, 'INFO', - 'Cleaning {} rows from {} table'.format(0, RefreshToken.__name__) + f'Cleaning {0} rows from {RefreshToken.__name__} table' ), ( LOGGER_NAME, 'INFO', - 'Cleaning {} rows from {} table'.format(0, AccessToken.__name__), + f'Cleaning {0} rows from {AccessToken.__name__} table', ), ( LOGGER_NAME, diff --git a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py index 183efc5047..a0c51d51b1 100644 --- a/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py +++ b/openedx/core/djangoapps/oauth_dispatch/tests/test_views.py @@ -59,7 +59,7 @@ class AccessTokenLoginMixin: return self.client.post( self.login_with_access_token_url, - HTTP_AUTHORIZATION="Bearer {}".format(access_token if access_token else self.access_token).encode('utf-8') + HTTP_AUTHORIZATION=f"Bearer {access_token if access_token else self.access_token}".encode('utf-8') ) def _assert_access_token_is_valid(self, access_token=None): diff --git a/openedx/core/djangoapps/profile_images/images.py b/openedx/core/djangoapps/profile_images/images.py index 64b6d215f7..63a367b056 100644 --- a/openedx/core/djangoapps/profile_images/images.py +++ b/openedx/core/djangoapps/profile_images/images.py @@ -244,4 +244,4 @@ def _user_friendly_size(size): while size >= 1024 and i < len(units): size //= 1024 i += 1 - return '{} {}'.format(size, units[i]) + return f'{size} {units[i]}' diff --git a/openedx/core/djangoapps/safe_sessions/middleware.py b/openedx/core/djangoapps/safe_sessions/middleware.py index 3abb622ed5..2541780a6e 100644 --- a/openedx/core/djangoapps/safe_sessions/middleware.py +++ b/openedx/core/djangoapps/safe_sessions/middleware.py @@ -390,8 +390,8 @@ class SafeSessionMiddleware(SessionMiddleware, MiddlewareMixin): if request.safe_cookie_verified_user_id != request.user.id and request.user.id is not None: log.warning( ( - "SafeCookieData user at request '{0}' does not match user at response: '{1}' " - "for request path '{2}'" + "SafeCookieData user at request '{}' does not match user at response: '{}' " + "for request path '{}'" ).format( # pylint: disable=logging-format-interpolation request.safe_cookie_verified_user_id, request.user.id, request.path, ), @@ -402,8 +402,8 @@ class SafeSessionMiddleware(SessionMiddleware, MiddlewareMixin): if request.safe_cookie_verified_user_id != userid_in_session and userid_in_session is not None: log.warning( ( - "SafeCookieData user at request '{0}' does not match user in session: '{1}' " - "for request path '{2}'" + "SafeCookieData user at request '{}' does not match user in session: '{}' " + "for request path '{}'" ).format( # pylint: disable=logging-format-interpolation request.safe_cookie_verified_user_id, userid_in_session, request.path, ), diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py index 36bed7e7fb..0850bf2aa6 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_course_update.py @@ -53,7 +53,7 @@ class TestSendCourseUpdate(ScheduleUpsellTestMixin, ScheduleSendEmailTestMixin, super().setUp() self.highlights_patcher = patch('openedx.core.djangoapps.schedules.resolvers.get_week_highlights') mock_highlights = self.highlights_patcher.start() - mock_highlights.return_value = ['Highlight {}'.format(num + 1) for num in range(3)] + mock_highlights.return_value = [f'Highlight {num + 1}' for num in range(3)] self.addCleanup(self.stop_highlights_patcher) def prepare_course_data(self, is_self_paced=True):