diff --git a/cms/djangoapps/contentstore/signals/handlers.py b/cms/djangoapps/contentstore/signals/handlers.py index b7fc7bc48b..478d99e94c 100644 --- a/cms/djangoapps/contentstore/signals/handlers.py +++ b/cms/djangoapps/contentstore/signals/handlers.py @@ -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) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 21a71b3f2f..343ff82740 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -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): """ diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index dc33590cd9..d0a81795ce 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -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)) diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 0c5002b4b6..9ecb7da2cd 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -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 ) diff --git a/cms/djangoapps/contentstore/tests/test_signals.py b/cms/djangoapps/contentstore/tests/test_signals.py index c2ceda240e..e7eb6eadc0 100644 --- a/cms/djangoapps/contentstore/tests/test_signals.py +++ b/cms/djangoapps/contentstore/tests/test_signals.py @@ -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) diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index 6bf82b8bf0..78210894cc 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -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 diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index bfc8a4b3b7..251771ac60 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -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 diff --git a/cms/djangoapps/contentstore/views/tests/test_certificates.py b/cms/djangoapps/contentstore/views/tests/test_certificates.py index 10ad19f03c..6fc77d910f 100644 --- a/cms/djangoapps/contentstore/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/views/tests/test_certificates.py @@ -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", diff --git a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py index 93f28b97ac..1fb7d8acfd 100644 --- a/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py +++ b/cms/djangoapps/contentstore/views/tests/test_entrance_exam.py @@ -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): diff --git a/cms/djangoapps/contentstore/views/tests/test_gating.py b/cms/djangoapps/contentstore/views/tests/test_gating.py index 4b2ccb0508..d2f5da1525 100644 --- a/cms/djangoapps/contentstore/views/tests/test_gating.py +++ b/cms/djangoapps/contentstore/views/tests/test_gating.py @@ -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) diff --git a/cms/djangoapps/contentstore/views/tests/test_helpers.py b/cms/djangoapps/contentstore/views/tests/test_helpers.py index ad4c349ced..1c8db5a9f3 100644 --- a/cms/djangoapps/contentstore/views/tests/test_helpers.py +++ b/cms/djangoapps/contentstore/views/tests/test_helpers.py @@ -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): diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index f14a2f5f29..aec9190c82 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -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)