BOM-2494: pyupgrade second iteration-VIII (#27448)
This commit is contained in:
@@ -35,7 +35,7 @@ def locked(expiry_seconds, key): # lint-amnesty, pylint: disable=missing-functi
|
||||
def task_decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
cache_key = '{}-{}'.format(func.__name__, kwargs[key])
|
||||
cache_key = f'{func.__name__}-{kwargs[key]}'
|
||||
if cache.add(cache_key, "true", expiry_seconds):
|
||||
log.info('Locking task in cache with key: %s for %s seconds', cache_key, expiry_seconds)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@@ -1895,7 +1895,7 @@ class RerunCourseTest(ContentStoreTestCase):
|
||||
|
||||
def get_unsucceeded_course_action_elements(self, html, course_key):
|
||||
"""Returns the elements in the unsucceeded course action section that have the given course_key"""
|
||||
return html.cssselect('.courses-processing li[data-course-key="{}"]'.format(str(course_key)))
|
||||
return html.cssselect(f'.courses-processing li[data-course-key="{str(course_key)}"]')
|
||||
|
||||
def assertInCourseListing(self, course_key):
|
||||
"""
|
||||
|
||||
@@ -1645,7 +1645,7 @@ class CourseGraderUpdatesTest(CourseTestCase):
|
||||
"short_label": "yo momma",
|
||||
"weight": 17.3,
|
||||
}
|
||||
resp = self.client.ajax_post('{}/{}'.format(self.url, len(self.starting_graders) + 1), grader)
|
||||
resp = self.client.ajax_post(f'{self.url}/{len(self.starting_graders) + 1}', grader)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
obj = json.loads(resp.content.decode('utf-8'))
|
||||
self.assertEqual(obj['id'], len(self.starting_graders))
|
||||
|
||||
@@ -188,7 +188,7 @@ class TestLibraries(LibraryTestCase):
|
||||
# Create many blocks in the library and add them to a course:
|
||||
for num in range(8):
|
||||
ItemFactory.create(
|
||||
data="This is #{}".format(num + 1),
|
||||
data=f"This is #{num + 1}",
|
||||
category="html", parent_location=self.library.location, user_id=self.user.id, publish_item=False
|
||||
)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class LockedTest(ModuleStoreTestCase):
|
||||
|
||||
handle_grading_policy_changed(sender, course_key=str(self.course.id))
|
||||
|
||||
cache_key = 'handle_grading_policy_changed-{}'.format(str(self.course.id))
|
||||
cache_key = f'handle_grading_policy_changed-{str(self.course.id)}'
|
||||
self.assertEqual(lock_available, compute_grades_async_mock.called)
|
||||
if lock_available:
|
||||
add_mock.assert_called_once_with(cache_key, "true", GRADING_POLICY_COUNTDOWN_SECONDS)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
""" Tests for utils. """
|
||||
import collections
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import mock
|
||||
from unittest.mock import Mock, patch
|
||||
from uuid import uuid4
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from mock import Mock, mock, patch
|
||||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator
|
||||
from path import Path as path
|
||||
from pytz import UTC
|
||||
|
||||
@@ -111,7 +111,7 @@ def reorder_tabs_handler(course_item, request):
|
||||
CourseTabList.validate_tabs(new_tab_list)
|
||||
except InvalidTabsException as exception:
|
||||
return JsonResponse(
|
||||
{"error": "New list of tabs is not valid: {}.".format(str(exception))}, status=400
|
||||
{"error": f"New list of tabs is not valid: {str(exception)}."}, status=400
|
||||
)
|
||||
|
||||
# persist the new order of the tabs
|
||||
|
||||
@@ -715,7 +715,7 @@ class CertificatesDetailHandlerTestCase(
|
||||
image_asset_location = AssetKey.from_string(signatory['signature_image_path'])
|
||||
content = contentstore().find(image_asset_location)
|
||||
self.assertIsNotNone(content)
|
||||
test_url = '{}/signatories/1'.format(self._url(cid=1))
|
||||
test_url = f'{self._url(cid=1)}/signatories/1'
|
||||
response = self.client.delete(
|
||||
test_url,
|
||||
content_type="application/json",
|
||||
@@ -737,7 +737,7 @@ class CertificatesDetailHandlerTestCase(
|
||||
Delete an signatory whose signature image is already removed or does not exist
|
||||
"""
|
||||
self._add_course_certificates(count=2, signatory_count=4, asset_path_format=signatory_path)
|
||||
test_url = '{}/signatories/3'.format(self._url(cid=1))
|
||||
test_url = f'{self._url(cid=1)}/signatories/3'
|
||||
response = self.client.delete(
|
||||
test_url,
|
||||
content_type="application/json",
|
||||
@@ -751,7 +751,7 @@ class CertificatesDetailHandlerTestCase(
|
||||
Try to delete a non existing certificate signatory. It should return status code 404 Not found.
|
||||
"""
|
||||
self._add_course_certificates(count=2)
|
||||
test_url = '{}/signatories/1'.format(self._url(cid=100))
|
||||
test_url = f'{self._url(cid=100)}/signatories/1'
|
||||
response = self.client.delete(
|
||||
test_url,
|
||||
content_type="application/json",
|
||||
|
||||
@@ -42,8 +42,8 @@ class EntranceExamHandlerTests(CourseTestCase, MilestonesTestCaseMixin):
|
||||
super().setUp()
|
||||
self.course_key = self.course.id
|
||||
self.usage_key = self.course.location
|
||||
self.course_url = '/course/{}'.format(str(self.course.id))
|
||||
self.exam_url = '/course/{}/entrance_exam/'.format(str(self.course.id))
|
||||
self.course_url = f'/course/{str(self.course.id)}'
|
||||
self.exam_url = f'/course/{str(self.course.id)}/entrance_exam/'
|
||||
self.milestone_relationship_types = milestones_helpers.get_milestone_relationship_types()
|
||||
|
||||
def test_entrance_exam_milestone_addition(self):
|
||||
|
||||
@@ -134,8 +134,8 @@ class TestSubsectionGating(CourseTestCase):
|
||||
mock_is_prereq.return_value = True
|
||||
mock_get_required_content.return_value = str(self.seq1.location), min_score, min_completion
|
||||
mock_get_prereqs.return_value = [
|
||||
{'namespace': '{}{}'.format(str(self.seq1.location), GATING_NAMESPACE_QUALIFIER)},
|
||||
{'namespace': '{}{}'.format(str(self.seq2.location), GATING_NAMESPACE_QUALIFIER)}
|
||||
{'namespace': f'{str(self.seq1.location)}{GATING_NAMESPACE_QUALIFIER}'},
|
||||
{'namespace': f'{str(self.seq2.location)}{GATING_NAMESPACE_QUALIFIER}'}
|
||||
]
|
||||
resp = json.loads(self.client.get_json(self.seq2_url).content.decode('utf-8'))
|
||||
mock_is_prereq.assert_called_with(self.course.id, self.seq2.location)
|
||||
|
||||
@@ -19,7 +19,7 @@ class HelpersTestCase(CourseTestCase):
|
||||
def test_xblock_studio_url(self):
|
||||
|
||||
# Verify course URL
|
||||
course_url = '/course/{}'.format(str(self.course.id))
|
||||
course_url = f'/course/{str(self.course.id)}'
|
||||
self.assertEqual(xblock_studio_url(self.course), course_url)
|
||||
|
||||
# Verify chapter URL
|
||||
@@ -27,7 +27,7 @@ class HelpersTestCase(CourseTestCase):
|
||||
display_name="Week 1")
|
||||
self.assertEqual(
|
||||
xblock_studio_url(chapter),
|
||||
'{}?show={}'.format(course_url, http.urlquote(str(chapter.location).encode()))
|
||||
f'{course_url}?show={http.urlquote(str(chapter.location).encode())}'
|
||||
)
|
||||
|
||||
# Verify sequential URL
|
||||
@@ -35,7 +35,7 @@ class HelpersTestCase(CourseTestCase):
|
||||
display_name="Lesson 1")
|
||||
self.assertEqual(
|
||||
xblock_studio_url(sequential),
|
||||
'{}?show={}'.format(course_url, http.urlquote(str(sequential.location).encode()))
|
||||
f'{course_url}?show={http.urlquote(str(sequential.location).encode())}'
|
||||
)
|
||||
|
||||
# Verify unit URL
|
||||
@@ -55,7 +55,7 @@ class HelpersTestCase(CourseTestCase):
|
||||
|
||||
# Verify library URL
|
||||
library = LibraryFactory.create()
|
||||
expected_url = '/library/{}'.format(str(library.location.library_key))
|
||||
expected_url = f'/library/{str(library.location.library_key)}'
|
||||
self.assertEqual(xblock_studio_url(library), expected_url)
|
||||
|
||||
def test_xblock_type_display_name(self):
|
||||
|
||||
@@ -113,7 +113,7 @@ class ImportEntranceExamTestCase(CourseTestCase, MilestonesTestCaseMixin):
|
||||
"""
|
||||
Check that pre existed entrance exam content should be overwrite with the imported course.
|
||||
"""
|
||||
exam_url = '/course/{}/entrance_exam/'.format(str(self.course.id))
|
||||
exam_url = f'/course/{str(self.course.id)}/entrance_exam/'
|
||||
resp = self.client.post(exam_url, {'entrance_exam_minimum_score_pct': 0.5}, http_accept='application/json')
|
||||
self.assertEqual(resp.status_code, 201)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user