Merge pull request #26939 from edx/content_type_gating-2

pyupgrade in content-type-gating
This commit is contained in:
Awais Qureshi
2021-03-17 17:33:21 +05:00
committed by GitHub
15 changed files with 38 additions and 49 deletions

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Django Admin pages for ContentTypeGatingConfig.
"""

View File

@@ -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,

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-08 19:43

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-19 14:59

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 19:07

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-11-28 20:21

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-06 15:47

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-08 14:47

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-11 19:19

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-03-13 16:34

View File

@@ -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,

View File

@@ -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.

View File

@@ -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()

View File

@@ -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))

View File

@@ -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