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