BOM-2331: Applied pylint-amnesty to waffle_utils, xblock, xmodule_django, zendesk_proxy, __init__.py
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""
|
||||
""" # lint-amnesty, pylint: disable=django-not-configured
|
||||
Extra utilities for waffle: most classes are defined in edx_toggles.toggles (https://edx-toggles.readthedocs.io/), but
|
||||
we keep here some extra classes for usage within edx-platform. These classes cover course override use cases.
|
||||
"""
|
||||
|
||||
@@ -21,7 +21,7 @@ TEST_WAFFLE_FLAG = WaffleFlag(TEST_WAFFLE_FLAG_NAMESPACE, "flag", __name__)
|
||||
|
||||
# TODO: Missing coverage for:
|
||||
# - computed_status
|
||||
class ToggleStateViewTests(TestCase):
|
||||
class ToggleStateViewTests(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
|
||||
def test_success_for_staff(self):
|
||||
response = self._get_toggle_state_response()
|
||||
@@ -159,7 +159,7 @@ class ToggleStateViewTests(TestCase):
|
||||
self.assertEqual("on", course_overrides["my.flag"]["course_overrides"][0]["force"])
|
||||
self.assertEqual("both", course_overrides["my.flag"]["computed_status"])
|
||||
|
||||
def _get_toggle_state_response(self, is_staff=True):
|
||||
def _get_toggle_state_response(self, is_staff=True): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
request = APIRequestFactory().get('/api/toggles/state/')
|
||||
user = UserFactory()
|
||||
user.is_staff = is_staff
|
||||
|
||||
@@ -24,7 +24,7 @@ class ToggleStateView(views.APIView):
|
||||
authentication_classes = (JwtAuthentication, SessionAuthentication,)
|
||||
permission_classes = (permissions.IsAuthenticated, IsStaff,)
|
||||
|
||||
def get(self, request):
|
||||
def get(self, request): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
response = OrderedDict()
|
||||
response['waffle_flags'] = _get_all_waffle_flags()
|
||||
response['waffle_switches'] = _get_all_waffle_switches()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
""" # lint-amnesty, pylint: disable=django-not-configured
|
||||
The new XBlock runtime and related code.
|
||||
"""
|
||||
|
||||
@@ -238,7 +238,7 @@ def get_handler_url(usage_key, handler_name, user):
|
||||
"""
|
||||
usage_key_str = six.text_type(usage_key)
|
||||
site_root_url = get_xblock_app_config().get_site_root_url()
|
||||
if not user:
|
||||
if not user: # lint-amnesty, pylint: disable=no-else-raise
|
||||
raise TypeError("Cannot get handler URLs without specifying a specific user ID.")
|
||||
elif user.is_authenticated:
|
||||
user_id = user.id
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from rest_framework import permissions
|
||||
from rest_framework.decorators import api_view, permission_classes, authentication_classes
|
||||
from rest_framework.decorators import api_view, permission_classes, authentication_classes # lint-amnesty, pylint: disable=unused-import
|
||||
from rest_framework.exceptions import PermissionDenied, AuthenticationFailed
|
||||
from rest_framework.response import Response
|
||||
from xblock.django.request import DjangoWebobRequest, webob_to_django_response
|
||||
@@ -135,7 +135,7 @@ def xblock_handler(request, user_id, secure_token, usage_key_str, handler_name,
|
||||
return response
|
||||
|
||||
|
||||
def cors_allow_xblock_handler(sender, request, **kwargs):
|
||||
def cors_allow_xblock_handler(sender, request, **kwargs): # lint-amnesty, pylint: disable=unused-argument
|
||||
"""
|
||||
Sandboxed XBlocks need to be able to call XBlock handlers via POST,
|
||||
from a different domain. See 'xblock_handler' method for details and how security is
|
||||
|
||||
@@ -103,7 +103,7 @@ class BlockstoreFieldData(FieldData):
|
||||
# (see _get_active_block()) and the value is an ActiveBlock object
|
||||
# (which holds olx_hash and changed_fields)
|
||||
self.active_blocks = WeakKeyDictionary()
|
||||
super(BlockstoreFieldData, self).__init__()
|
||||
super(BlockstoreFieldData, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def _getfield(self, block, name):
|
||||
"""
|
||||
@@ -125,7 +125,7 @@ class BlockstoreFieldData(FieldData):
|
||||
if name == CHILDREN_INCLUDES:
|
||||
return # This is a pseudo-field used in conjunction with BlockstoreChildrenData
|
||||
field = self._getfield(block, name)
|
||||
if field.scope in (Scope.children, Scope.parent):
|
||||
if field.scope in (Scope.children, Scope.parent): # lint-amnesty, pylint: disable=no-else-raise
|
||||
# This field data store is focused on definition-level field data, and children/parent is mostly
|
||||
# relevant at the usage level. Scope.parent doesn't even seem to be used?
|
||||
raise NotImplementedError("Setting Scope.children/parent is not supported by BlockstoreFieldData.")
|
||||
@@ -278,7 +278,7 @@ class BlockstoreChildrenData(FieldData):
|
||||
"""
|
||||
# The data store that holds Scope.usage and Scope.definition data:
|
||||
self.authored_data_store = blockstore_field_data
|
||||
super(BlockstoreChildrenData, self).__init__()
|
||||
super(BlockstoreChildrenData, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def _check_field(self, block, name): # pylint: disable=unused-argument
|
||||
"""
|
||||
|
||||
@@ -47,7 +47,7 @@ class BlockstoreXBlockRuntime(XBlockRuntime):
|
||||
try:
|
||||
block_type = self.id_reader.get_block_type(def_id)
|
||||
except NoSuchDefinition:
|
||||
raise NoSuchUsage(repr(usage_id))
|
||||
raise NoSuchUsage(repr(usage_id)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
keys = ScopeIds(self.user_id, block_type, def_id, usage_id)
|
||||
|
||||
if self.system.authored_data_store.has_cached_definition(def_id):
|
||||
@@ -192,7 +192,7 @@ def xml_for_definition(definition_key):
|
||||
draft_name=definition_key.draft_name,
|
||||
)
|
||||
except blockstore_api.BundleFileNotFound:
|
||||
raise NoSuchDefinition("OLX file {} not found in bundle {}.".format(
|
||||
raise NoSuchDefinition("OLX file {} not found in bundle {}.".format( # lint-amnesty, pylint: disable=raise-missing-from
|
||||
definition_key.olx_path, definition_key.bundle_uuid,
|
||||
))
|
||||
node = etree.fromstring(xml_str)
|
||||
|
||||
@@ -36,7 +36,7 @@ class LmsBlockMixin(XBlockMixin):
|
||||
Copied from lms.djangoapps.lms_xblock.mixin.LmsBlockMixin
|
||||
"""
|
||||
completion_service = self.runtime.service(self, 'completion')
|
||||
if completion_service is None:
|
||||
if completion_service is None: # lint-amnesty, pylint: disable=no-else-raise
|
||||
raise JsonHandlerError(500, u"No completion service found")
|
||||
elif not completion_service.completion_tracking_enabled():
|
||||
raise JsonHandlerError(404, u"Completion tracking is not enabled and API calls are unexpected")
|
||||
|
||||
@@ -33,7 +33,7 @@ def parse_xblock_include(include_node):
|
||||
try:
|
||||
definition_path = include_node.attrib['definition']
|
||||
except KeyError:
|
||||
raise BundleFormatException("<xblock-include> is missing the required definition=\"...\" attribute")
|
||||
raise BundleFormatException("<xblock-include> is missing the required definition=\"...\" attribute") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
usage_hint = include_node.attrib.get("usage", None)
|
||||
link_id = include_node.attrib.get("source", None)
|
||||
# This is pointing to another definition in the same bundle. It looks like:
|
||||
@@ -41,7 +41,7 @@ def parse_xblock_include(include_node):
|
||||
try:
|
||||
block_type, definition_id = definition_path.split("/")
|
||||
except ValueError:
|
||||
raise BundleFormatException("Invalid definition attribute: {}".format(definition_path))
|
||||
raise BundleFormatException("Invalid definition attribute: {}".format(definition_path)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return XBlockInclude(link_id=link_id, block_type=block_type, definition_id=definition_id, usage_hint=usage_hint)
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ def definition_for_include(parsed_include, parent_definition_key):
|
||||
try:
|
||||
link = links[parsed_include.link_id]
|
||||
except KeyError:
|
||||
raise BundleFormatException("Link not found: {}".format(parsed_include.link_id))
|
||||
raise BundleFormatException("Link not found: {}".format(parsed_include.link_id)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return BundleDefinitionLocator(
|
||||
bundle_uuid=link.bundle_uuid,
|
||||
block_type=parsed_include.block_type,
|
||||
|
||||
@@ -72,7 +72,7 @@ class XBlockRuntime(RuntimeShim, Runtime):
|
||||
suppports_state_for_anonymous_users = True
|
||||
|
||||
def __init__(self, system, user):
|
||||
super(XBlockRuntime, self).__init__(
|
||||
super(XBlockRuntime, self).__init__( # lint-amnesty, pylint: disable=super-with-arguments
|
||||
id_reader=system.id_reader,
|
||||
mixins=(
|
||||
LmsBlockMixin, # Adds Non-deprecated LMS/Studio functionality
|
||||
@@ -234,7 +234,7 @@ class XBlockRuntime(RuntimeShim, Runtime):
|
||||
# Otherwise, fall back to the base implementation which loads services
|
||||
# defined in the constructor:
|
||||
if service is None:
|
||||
service = super(XBlockRuntime, self).service(block, service_name)
|
||||
service = super(XBlockRuntime, self).service(block, service_name) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
return service
|
||||
|
||||
def _init_field_data_for_block(self, block):
|
||||
@@ -291,7 +291,7 @@ class XBlockRuntime(RuntimeShim, Runtime):
|
||||
# which create relative URLs (/static/studio/bundles/webpack-foo.js).
|
||||
# We want all resource URLs to be absolute, such as is done when
|
||||
# local_resource_url() is used.
|
||||
fragment = super(XBlockRuntime, self).render(block, view_name, context)
|
||||
fragment = super(XBlockRuntime, self).render(block, view_name, context) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
needs_fix = False
|
||||
for resource in fragment.resources:
|
||||
if resource.kind == 'url' and resource.data.startswith('/'):
|
||||
|
||||
@@ -71,7 +71,7 @@ def serialize_xblock(block):
|
||||
try:
|
||||
child_includes = block.runtime.child_includes_of(block)
|
||||
except AttributeError:
|
||||
raise RuntimeError("Cannot get child includes of block. Make sure it's using BlockstoreXBlockRuntime")
|
||||
raise RuntimeError("Cannot get child includes of block. Make sure it's using BlockstoreXBlockRuntime") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
if len(child_includes) != len(block.children):
|
||||
raise RuntimeError(
|
||||
"Mistmatch between block.children and runtime.child_includes_of()."
|
||||
@@ -123,7 +123,7 @@ def override_export_fs(block):
|
||||
XmlParserMixin.export_to_file = lambda _: False # So this applies to child blocks that get loaded during export
|
||||
try:
|
||||
yield fs
|
||||
except:
|
||||
except: # lint-amnesty, pylint: disable=try-except-raise
|
||||
raise
|
||||
finally:
|
||||
block.runtime.export_fs = old_export_fs
|
||||
|
||||
@@ -24,7 +24,7 @@ class RuntimeShim(object):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RuntimeShim, self).__init__(*args, **kwargs)
|
||||
super(RuntimeShim, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self._active_block = None
|
||||
|
||||
def render(self, block, view_name, context=None):
|
||||
@@ -40,7 +40,7 @@ class RuntimeShim(object):
|
||||
old_active_block = self._active_block
|
||||
self._active_block = block
|
||||
try:
|
||||
return super(RuntimeShim, self).render(block, view_name, context)
|
||||
return super(RuntimeShim, self).render(block, view_name, context) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
finally:
|
||||
# Reset the active view to what it was before entering this method
|
||||
self._active_block = old_active_block
|
||||
@@ -53,7 +53,7 @@ class RuntimeShim(object):
|
||||
old_active_block = self._active_block
|
||||
self._active_block = block
|
||||
try:
|
||||
return super(RuntimeShim, self).handle(block, handler_name, request, suffix)
|
||||
return super(RuntimeShim, self).handle(block, handler_name, request, suffix) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
finally:
|
||||
# Reset the active view to what it was before entering this method
|
||||
self._active_block = old_active_block
|
||||
@@ -358,7 +358,7 @@ class RuntimeShim(object):
|
||||
Get the list of CSS classes that the wrapping <div> should have for the
|
||||
specified xblock or aside's view.
|
||||
"""
|
||||
css_classes = super(RuntimeShim, self)._css_classes_for(block, view)
|
||||
css_classes = super(RuntimeShim, self)._css_classes_for(block, view) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
# Many CSS styles for former XModules use
|
||||
# .xmodule_display.xmodule_VideoBlock
|
||||
# as their selector, so add those classes:
|
||||
|
||||
@@ -7,7 +7,7 @@ import pytest
|
||||
from django.test import override_settings
|
||||
from freezegun import freeze_time
|
||||
|
||||
from openedx.core.djangoapps.xblock.utils import (
|
||||
from openedx.core.djangoapps.xblock.utils import ( # lint-amnesty, pylint: disable=reimported
|
||||
get_secure_token_for_xblock_handler,
|
||||
validate_secure_token_for_xblock_handler,
|
||||
_get_secure_token_for_xblock_handler,
|
||||
|
||||
@@ -10,7 +10,7 @@ from uuid import uuid4
|
||||
|
||||
import crum
|
||||
from django.conf import settings
|
||||
from six import text_type
|
||||
from six import text_type # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
|
||||
def get_secure_token_for_xblock_handler(user_id, block_key_str, time_idx=0):
|
||||
|
||||
@@ -44,7 +44,7 @@ class NoneToEmptyQuerySet(models.query.QuerySet):
|
||||
if key in kwargs and kwargs[key] is None:
|
||||
kwargs[key] = field_object.Empty
|
||||
|
||||
return super(NoneToEmptyQuerySet, self)._filter_or_exclude(*args, **kwargs)
|
||||
return super(NoneToEmptyQuerySet, self)._filter_or_exclude(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class OpaqueKeyField(opaque_keys.edx.django.models.OpaqueKeyField):
|
||||
@@ -61,7 +61,7 @@ class OpaqueKeyField(opaque_keys.edx.django.models.OpaqueKeyField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("openedx.core.djangoapps.xmodule_django.models.OpaqueKeyField is deprecated. "
|
||||
"Please use opaque_keys.edx.django.models.OpaqueKeyField instead.", stacklevel=2)
|
||||
super(OpaqueKeyField, self).__init__(*args, **kwargs)
|
||||
super(OpaqueKeyField, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class CourseKeyField(opaque_keys.edx.django.models.CourseKeyField):
|
||||
@@ -71,7 +71,7 @@ class CourseKeyField(opaque_keys.edx.django.models.CourseKeyField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("openedx.core.djangoapps.xmodule_django.models.LocationKeyField is deprecated. "
|
||||
"Please use opaque_keys.edx.django.models.UsageKeyField instead.", stacklevel=2)
|
||||
super(CourseKeyField, self).__init__(*args, **kwargs)
|
||||
super(CourseKeyField, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class UsageKeyField(opaque_keys.edx.django.models.UsageKeyField):
|
||||
@@ -81,7 +81,7 @@ class UsageKeyField(opaque_keys.edx.django.models.UsageKeyField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("openedx.core.djangoapps.xmodule_django.models.UsageKeyField is deprecated. "
|
||||
"Please use opaque_keys.edx.django.models.UsageKeyField instead.", stacklevel=2)
|
||||
super(UsageKeyField, self).__init__(*args, **kwargs)
|
||||
super(UsageKeyField, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class UsageKeyWithRunField(opaque_keys.edx.django.models.UsageKeyField):
|
||||
@@ -90,7 +90,7 @@ class UsageKeyWithRunField(opaque_keys.edx.django.models.UsageKeyField):
|
||||
missing `run` values, for old Mongo courses.
|
||||
"""
|
||||
def to_python(self, value):
|
||||
value = super(UsageKeyWithRunField, self).to_python(value)
|
||||
value = super(UsageKeyWithRunField, self).to_python(value) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
if value is not None and value.run is None:
|
||||
value = value.replace(course_key=modulestore().fill_in_run(value.course_key))
|
||||
return value
|
||||
@@ -103,4 +103,4 @@ class BlockTypeKeyField(opaque_keys.edx.django.models.BlockTypeKeyField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn("openedx.core.djangoapps.xmodule_django.models.BlockTypeKeyField is deprecated. "
|
||||
"Please use opaque_keys.edx.django.models.BlockTypeKeyField instead.", stacklevel=2)
|
||||
super(BlockTypeKeyField, self).__init__(*args, **kwargs)
|
||||
super(BlockTypeKeyField, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@@ -20,7 +20,7 @@ from openedx.core.lib.api.test_utils import ApiTestCase
|
||||
ZENDESK_OAUTH_ACCESS_TOKEN="abcdefghijklmnopqrstuvwxyz1234567890",
|
||||
ZENDESK_GROUP_ID_MAPPING={"Financial Assistance": 123},
|
||||
)
|
||||
class TestUtils(ApiTestCase):
|
||||
class TestUtils(ApiTestCase): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
def setUp(self):
|
||||
self.request_data = {
|
||||
'email': 'JohnQStudent@example.com',
|
||||
@@ -28,7 +28,7 @@ class TestUtils(ApiTestCase):
|
||||
'subject': 'Python Unit Test Help Request',
|
||||
'body': "Help! I'm trapped in a unit test factory and I can't get out!",
|
||||
}
|
||||
return super(TestUtils, self).setUp()
|
||||
return super(TestUtils, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@override_settings(
|
||||
ZENDESK_URL=None,
|
||||
|
||||
@@ -34,7 +34,7 @@ class ZendeskProxyTestCase(ApiTestCase):
|
||||
'message': "Help! I'm trapped in a unit test factory and I can't get out!",
|
||||
}
|
||||
}
|
||||
return super(ZendeskProxyTestCase, self).setUp()
|
||||
return super(ZendeskProxyTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def test_post(self):
|
||||
with patch('requests.post', return_value=MagicMock(status_code=201)) as mock_post:
|
||||
|
||||
@@ -45,7 +45,7 @@ class ZendeskProxyTestCase(ApiTestCase):
|
||||
}
|
||||
],
|
||||
}
|
||||
return super(ZendeskProxyTestCase, self).setUp()
|
||||
return super(ZendeskProxyTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def test_post(self):
|
||||
with patch('requests.post', return_value=MagicMock(status_code=201)) as mock_post:
|
||||
|
||||
@@ -19,7 +19,7 @@ class ZendeskProxyThrottle(SimpleRateThrottle):
|
||||
"""
|
||||
def __init__(self):
|
||||
self.rate = '{}/hour'.format(ZENDESK_REQUESTS_PER_HOUR)
|
||||
super(ZendeskProxyThrottle, self).__init__()
|
||||
super(ZendeskProxyThrottle, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def get_cache_key(self, request, view):
|
||||
"""
|
||||
|
||||
@@ -22,7 +22,7 @@ class ZendeskProxyThrottle(UserRateThrottle):
|
||||
|
||||
def __init__(self):
|
||||
self.rate = '{}/hour'.format(REQUESTS_PER_HOUR)
|
||||
super(ZendeskProxyThrottle, self).__init__()
|
||||
super(ZendeskProxyThrottle, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class ZendeskPassthroughView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user