From 66bd34743c79a1fe35e3c28e0ba0980ab93e7ac7 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Wed, 10 Mar 2021 18:31:46 +0500 Subject: [PATCH] BOM-2442 pyupgrade in content-type-gating --- openedx/features/content_type_gating/admin.py | 1 - .../features/content_type_gating/helpers.py | 4 +-- .../migrations/0001_initial.py | 1 - .../migrations/0002_auto_20181119_0959.py | 1 - .../migrations/0003_auto_20181128_1407.py | 1 - .../migrations/0004_auto_20181128_1521.py | 1 - .../migrations/0005_auto_20190306_1547.py | 1 - .../migrations/0006_auto_20190308_1447.py | 1 - .../migrations/0007_auto_20190311_1919.py | 1 - .../migrations/0008_auto_20190313_1634.py | 1 - .../content_type_gating/partitions.py | 24 ++++++------- .../features/content_type_gating/services.py | 2 +- .../content_type_gating/tests/test_access.py | 36 +++++++++---------- .../content_type_gating/tests/test_models.py | 8 ++--- .../tests/test_partitions.py | 4 +-- 15 files changed, 38 insertions(+), 49 deletions(-) diff --git a/openedx/features/content_type_gating/admin.py b/openedx/features/content_type_gating/admin.py index e02b632977..3f4f58d258 100644 --- a/openedx/features/content_type_gating/admin.py +++ b/openedx/features/content_type_gating/admin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Django Admin pages for ContentTypeGatingConfig. """ diff --git a/openedx/features/content_type_gating/helpers.py b/openedx/features/content_type_gating/helpers.py index b0c0bb4fec..6a78eae635 100644 --- a/openedx/features/content_type_gating/helpers.py +++ b/openedx/features/content_type_gating/helpers.py @@ -56,8 +56,8 @@ def correct_modes_for_fbe(course_key=None, enrollment=None, user=None, course=No ) if course_mode is None: LOG.error( - u"User %s is in an unknown CourseMode '%s'" - u" for course %s. Granting full access to content for this user", + "User %s is in an unknown CourseMode '%s'" + " for course %s. Granting full access to content for this user", user.username, mode_slug, course_key, diff --git a/openedx/features/content_type_gating/migrations/0001_initial.py b/openedx/features/content_type_gating/migrations/0001_initial.py index 6b1013663a..eb0499ba78 100644 --- a/openedx/features/content_type_gating/migrations/0001_initial.py +++ b/openedx/features/content_type_gating/migrations/0001_initial.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.16 on 2018-11-08 19:43 diff --git a/openedx/features/content_type_gating/migrations/0002_auto_20181119_0959.py b/openedx/features/content_type_gating/migrations/0002_auto_20181119_0959.py index e8013d967d..0d362fd01a 100644 --- a/openedx/features/content_type_gating/migrations/0002_auto_20181119_0959.py +++ b/openedx/features/content_type_gating/migrations/0002_auto_20181119_0959.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.16 on 2018-11-19 14:59 diff --git a/openedx/features/content_type_gating/migrations/0003_auto_20181128_1407.py b/openedx/features/content_type_gating/migrations/0003_auto_20181128_1407.py index 963b20e40d..00bbae1082 100644 --- a/openedx/features/content_type_gating/migrations/0003_auto_20181128_1407.py +++ b/openedx/features/content_type_gating/migrations/0003_auto_20181128_1407.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.16 on 2018-11-28 19:07 diff --git a/openedx/features/content_type_gating/migrations/0004_auto_20181128_1521.py b/openedx/features/content_type_gating/migrations/0004_auto_20181128_1521.py index 6f131e7f17..bebc09b59f 100644 --- a/openedx/features/content_type_gating/migrations/0004_auto_20181128_1521.py +++ b/openedx/features/content_type_gating/migrations/0004_auto_20181128_1521.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.16 on 2018-11-28 20:21 diff --git a/openedx/features/content_type_gating/migrations/0005_auto_20190306_1547.py b/openedx/features/content_type_gating/migrations/0005_auto_20190306_1547.py index 07d67c9dfa..9306d64e03 100644 --- a/openedx/features/content_type_gating/migrations/0005_auto_20190306_1547.py +++ b/openedx/features/content_type_gating/migrations/0005_auto_20190306_1547.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.20 on 2019-03-06 15:47 diff --git a/openedx/features/content_type_gating/migrations/0006_auto_20190308_1447.py b/openedx/features/content_type_gating/migrations/0006_auto_20190308_1447.py index 55af9e4937..577106a44f 100644 --- a/openedx/features/content_type_gating/migrations/0006_auto_20190308_1447.py +++ b/openedx/features/content_type_gating/migrations/0006_auto_20190308_1447.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.20 on 2019-03-08 14:47 diff --git a/openedx/features/content_type_gating/migrations/0007_auto_20190311_1919.py b/openedx/features/content_type_gating/migrations/0007_auto_20190311_1919.py index af96dee217..77d64d8069 100644 --- a/openedx/features/content_type_gating/migrations/0007_auto_20190311_1919.py +++ b/openedx/features/content_type_gating/migrations/0007_auto_20190311_1919.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.20 on 2019-03-11 19:19 diff --git a/openedx/features/content_type_gating/migrations/0008_auto_20190313_1634.py b/openedx/features/content_type_gating/migrations/0008_auto_20190313_1634.py index 4b1af6cd33..d1b08ffc98 100644 --- a/openedx/features/content_type_gating/migrations/0008_auto_20190313_1634.py +++ b/openedx/features/content_type_gating/migrations/0008_auto_20190313_1634.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.11.20 on 2019-03-13 16:34 diff --git a/openedx/features/content_type_gating/partitions.py b/openedx/features/content_type_gating/partitions.py index 0394ac677c..f59ca6327c 100644 --- a/openedx/features/content_type_gating/partitions.py +++ b/openedx/features/content_type_gating/partitions.py @@ -44,22 +44,22 @@ def create_content_gating_partition(course): content_gate_scheme = UserPartition.get_scheme(CONTENT_TYPE_GATING_SCHEME) except UserPartitionError: LOG.warning( - u"No %r scheme registered, ContentTypeGatingPartitionScheme will not be created.", + "No %r scheme registered, ContentTypeGatingPartitionScheme will not be created.", CONTENT_TYPE_GATING_SCHEME ) return None - used_ids = set(p.id for p in course.user_partitions) + used_ids = {p.id for p in course.user_partitions} if CONTENT_GATING_PARTITION_ID in used_ids: # It's possible for course authors to add arbitrary partitions via XML import. If they do, and create a # partition with id 51, it will collide with the Content Gating Partition. We'll catch that here, and # then fix the course content as needed (or get the course team to). LOG.warning( - u"Can't add %r partition, as ID %r is assigned to %r in course %s.", + "Can't add %r partition, as ID %r is assigned to %r in course %s.", CONTENT_TYPE_GATING_SCHEME, CONTENT_GATING_PARTITION_ID, _get_partition_from_id(course.user_partitions, CONTENT_GATING_PARTITION_ID).name, - six.text_type(course.id), + str(course.id), ) return None @@ -67,9 +67,9 @@ def create_content_gating_partition(course): id=CONTENT_GATING_PARTITION_ID, # Content gating partition name should not be marked for translations # edX mobile apps expect it in english - name=u"Feature-based Enrollments", - description=_(u"Partition for segmenting users by access to gated content types"), - parameters={"course_id": six.text_type(course.id)} + name="Feature-based Enrollments", + description=_("Partition for segmenting users by access to gated content types"), + parameters={"course_id": str(course.id)} ) return partition @@ -115,9 +115,9 @@ class ContentTypeGatingPartition(UserPartition): request = crum.get_current_request() if request and is_request_from_mobile_app(request): - return _(u"Graded assessments are available to Verified Track learners.") + return _("Graded assessments are available to Verified Track learners.") else: - return _(u"Graded assessments are available to Verified Track learners. Upgrade to Unlock.") + return _("Graded assessments are available to Verified Track learners. Upgrade to Unlock.") def _get_checkout_link(self, user, sku): ecomm_service = EcommerceService() @@ -132,7 +132,7 @@ class ContentTypeGatingPartition(UserPartition): return block.scope_ids.usage_id.course_key -class ContentTypeGatingPartitionScheme(object): +class ContentTypeGatingPartitionScheme: """ This scheme implements the Content Type Gating permission partitioning. @@ -171,8 +171,8 @@ class ContentTypeGatingPartitionScheme(object): """ return ContentTypeGatingPartition( id, - six.text_type(name), - six.text_type(description), + str(name), + str(description), [ LIMITED_ACCESS, FULL_ACCESS, diff --git a/openedx/features/content_type_gating/services.py b/openedx/features/content_type_gating/services.py index f7b2381867..363fd81688 100644 --- a/openedx/features/content_type_gating/services.py +++ b/openedx/features/content_type_gating/services.py @@ -11,7 +11,7 @@ from openedx.core.lib.graph_traversals import get_children, leaf_filter, travers from openedx.features.content_type_gating.models import ContentTypeGatingConfig -class ContentTypeGatingService(object): +class ContentTypeGatingService: """ Content Type Gating uses Block Transformers to gate sections of the course outline and field overrides to gate course content. diff --git a/openedx/features/content_type_gating/tests/test_access.py b/openedx/features/content_type_gating/tests/test_access.py index 8b2d0357c0..596fcf0e1d 100644 --- a/openedx/features/content_type_gating/tests/test_access.py +++ b/openedx/features/content_type_gating/tests/test_access.py @@ -15,7 +15,7 @@ from django.test.utils import override_settings from django.urls import reverse from django.utils import timezone from django.contrib.auth.models import User -from mock import patch, Mock +from unittest.mock import patch, Mock from pyquery import PyQuery as pq from lms.djangoapps.course_api.blocks.api import get_blocks @@ -76,8 +76,8 @@ def _get_content_from_fragment(block, user_id, course, request_factory, mock_get block = load_single_xblock( request=fake_request, user_id=user_id, - course_id=six.text_type(course.id), - usage_key_string=six.text_type(block.scope_ids.usage_id), + course_id=str(course.id), + usage_key_string=str(block.scope_ids.usage_id), course=course, will_recheck_access=True, ) @@ -103,7 +103,7 @@ def _get_content_from_lms_index(block, user_id, course, request_factory): page = pq(page_content.content) seq_contents = page('#seq_contents_0').html() seq = pq(seq_contents) - block_contents = seq('[data-id="{}"]'.format(block.scope_ids.usage_id)) + block_contents = seq(f'[data-id="{block.scope_ids.usage_id}"]') return block_contents.html() @@ -186,7 +186,7 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): @classmethod def setUpClass(cls): - super(TestProblemTypeAccess, cls).setUpClass() + super().setUpClass() cls.factory = RequestFactory() cls.courses = {} @@ -337,7 +337,7 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): ) def setUp(self): - super(TestProblemTypeAccess, self).setUp() + super().setUp() # enroll all users into the all track types course self.users = {} @@ -557,8 +557,8 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): url = reverse( 'xblock_handler', kwargs={ - 'course_id': six.text_type(self.course.id), - 'usage_id': quote_slashes(six.text_type(problem_location)), + 'course_id': str(self.course.id), + 'usage_id': quote_slashes(str(problem_location)), 'handler': 'xmodule_handler', 'suffix': 'problem_show', } @@ -681,7 +681,7 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): self.update_masquerade(**masquerade_config) block = self.blocks_dict['problem'] - block_view_url = reverse('render_xblock', kwargs={'usage_key_string': six.text_type(block.scope_ids.usage_id)}) + block_view_url = reverse('render_xblock', kwargs={'usage_key_string': str(block.scope_ids.usage_id)}) response = self.client.get(block_view_url) if is_gated: assert response.status_code == 404 @@ -719,7 +719,7 @@ class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): self.update_masquerade(username=user.username) block = self.blocks_dict['problem'] - block_view_url = reverse('render_xblock', kwargs={'usage_key_string': six.text_type(block.scope_ids.usage_id)}) + block_view_url = reverse('render_xblock', kwargs={'usage_key_string': str(block.scope_ids.usage_id)}) response = self.client.get(block_view_url) assert response.status_code == 200 @@ -788,12 +788,12 @@ class TestConditionalContentAccess(TestConditionalContent): """ @classmethod def setUpClass(cls): - super(TestConditionalContentAccess, cls).setUpClass() + super().setUpClass() cls.factory = RequestFactory() ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1)) def setUp(self): - super(TestConditionalContentAccess, self).setUp() + super().setUp() # Add a verified mode to the course CourseModeFactory.create(course_id=self.course.id, mode_slug='audit') @@ -813,14 +813,14 @@ class TestConditionalContentAccess(TestConditionalContent): UserCourseTagFactory( user=self.student_verified_a, course_id=self.course.id, - key='xblock.partition_service.partition_{0}'.format(self.partition.id), - value=str('0'), + key=f'xblock.partition_service.partition_{self.partition.id}', + value='0', ) UserCourseTagFactory( user=self.student_verified_b, course_id=self.course.id, - key='xblock.partition_service.partition_{0}'.format(self.partition.id), - value=str('1'), + key=f'xblock.partition_service.partition_{self.partition.id}', + value='1', ) # Create blocks to go into the verticals self.block_a = ItemFactory.create( @@ -890,7 +890,7 @@ class TestMessageDeduplication(ModuleStoreTestCase): """ def setUp(self): - super(TestMessageDeduplication, self).setUp() + super().setUp() self.user = UserFactory.create() self.request_factory = RequestFactory() @@ -1099,7 +1099,7 @@ class TestContentTypeGatingService(ModuleStoreTestCase): """ def setUp(self): - super(TestContentTypeGatingService, self).setUp() + super().setUp() self.user = UserFactory.create() self.request_factory = RequestFactory() diff --git a/openedx/features/content_type_gating/tests/test_models.py b/openedx/features/content_type_gating/tests/test_models.py index 9c4bb7f77b..f261b02588 100644 --- a/openedx/features/content_type_gating/tests/test_models.py +++ b/openedx/features/content_type_gating/tests/test_models.py @@ -8,7 +8,7 @@ import ddt import pytz from django.utils import timezone from edx_django_utils.cache import RequestCache -from mock import Mock +from unittest.mock import Mock from opaque_keys.edx.locator import CourseLocator from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -31,7 +31,7 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase): CourseModeFactory.create(course_id=self.course_overview.id, mode_slug='audit') CourseModeFactory.create(course_id=self.course_overview.id, mode_slug='verified') self.user = UserFactory.create() - super(TestContentTypeGatingConfig, self).setUp() + super().setUp() @ddt.data( (True, True), @@ -173,7 +173,7 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase): ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)) for org_setting in (True, False, None): - test_org = "{}-{}".format(test_site_cfg.id, org_setting) + test_org = f"{test_site_cfg.id}-{org_setting}" test_site_cfg.site_values['course_org_filter'].append(test_org) test_site_cfg.save() @@ -182,7 +182,7 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase): for course_setting in (True, False, None): test_course = CourseOverviewFactory.create( org=test_org, - id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting)) + id=CourseLocator(test_org, 'test_course', f'run-{course_setting}') ) ContentTypeGatingConfig.objects.create(course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)) diff --git a/openedx/features/content_type_gating/tests/test_partitions.py b/openedx/features/content_type_gating/tests/test_partitions.py index e51ecb2261..7dffe8d954 100644 --- a/openedx/features/content_type_gating/tests/test_partitions.py +++ b/openedx/features/content_type_gating/tests/test_partitions.py @@ -1,10 +1,8 @@ - - from datetime import datetime from django.conf import settings from django.test import RequestFactory -from mock import Mock, patch +from unittest.mock import Mock, patch from opaque_keys.edx.keys import CourseKey from common.djangoapps.course_modes.tests.factories import CourseModeFactory