From e9b167e1fdc179da8f0d1553a6aca1536fb28294 Mon Sep 17 00:00:00 2001 From: Jawayria Date: Mon, 1 Feb 2021 18:38:01 +0500 Subject: [PATCH 1/2] Applied pylint-amnesty to course_api --- lms/djangoapps/course_api/__init__.py | 2 +- lms/djangoapps/course_api/api.py | 4 ++-- lms/djangoapps/course_api/blocks/forms.py | 10 ++++---- .../course_api/blocks/permissions.py | 4 ++-- .../course_api/blocks/serializers.py | 2 +- .../course_api/blocks/tests/test_api.py | 6 ++--- .../course_api/blocks/tests/test_forms.py | 2 +- .../blocks/tests/test_serializers.py | 2 +- .../course_api/blocks/tests/test_views.py | 4 ++-- .../blocks/transformers/milestones.py | 6 ++--- .../tests/test_block_completion.py | 4 ++-- .../transformers/tests/test_block_counts.py | 2 +- .../transformers/tests/test_extra_fields.py | 2 +- .../transformers/tests/test_milestones.py | 6 ++--- .../transformers/tests/test_student_view.py | 2 +- .../transformers/tests/test_video_urls.py | 2 +- lms/djangoapps/course_api/blocks/views.py | 7 +++--- lms/djangoapps/course_api/forms.py | 4 ++-- lms/djangoapps/course_api/serializers.py | 14 +++++------ lms/djangoapps/course_api/tests/test_api.py | 2 +- lms/djangoapps/course_api/tests/test_forms.py | 8 +++---- .../course_api/tests/test_serializers.py | 8 +++---- lms/djangoapps/course_api/tests/test_views.py | 10 ++++---- lms/djangoapps/course_api/views.py | 24 +++++++++---------- 24 files changed, 69 insertions(+), 68 deletions(-) diff --git a/lms/djangoapps/course_api/__init__.py b/lms/djangoapps/course_api/__init__.py index f74c37503c..b12d80613d 100644 --- a/lms/djangoapps/course_api/__init__.py +++ b/lms/djangoapps/course_api/__init__.py @@ -1,4 +1,4 @@ -""" Course API """ +""" Course API """ # lint-amnesty, pylint: disable=django-not-configured from edx_toggles.toggles import LegacyWaffleSwitch, LegacyWaffleSwitchNamespace diff --git a/lms/djangoapps/course_api/api.py b/lms/djangoapps/course_api/api.py index 86c9fe6ba8..cbc84c8309 100644 --- a/lms/djangoapps/course_api/api.py +++ b/lms/djangoapps/course_api/api.py @@ -6,7 +6,7 @@ import logging from edx_django_utils.monitoring import function_trace from edx_when.api import get_dates_for_course from django.conf import settings -from django.contrib.auth.models import AnonymousUser, User +from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from django.urls import reverse from rest_framework.exceptions import PermissionDenied import search @@ -18,7 +18,7 @@ from lms.djangoapps.courseware.courses import ( get_courses, get_permission_for_course_about ) -from opaque_keys.edx.django.models import CourseKeyField +from opaque_keys.edx.django.models import CourseKeyField # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.lib.api.view_utils import LazySequence from common.djangoapps.student.models import CourseAccessRole diff --git a/lms/djangoapps/course_api/blocks/forms.py b/lms/djangoapps/course_api/blocks/forms.py index 96c7946e0b..ee8ea5d77b 100644 --- a/lms/djangoapps/course_api/blocks/forms.py +++ b/lms/djangoapps/course_api/blocks/forms.py @@ -3,7 +3,7 @@ Course API Forms """ -from django.contrib.auth.models import AnonymousUser, User +from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from django.core.exceptions import ValidationError from django.forms import CharField, ChoiceField, Form, IntegerField from django.http import Http404 @@ -48,7 +48,7 @@ class BlockListGetForm(Form): try: return int(value) except ValueError: - raise ValidationError("'{}' is not a valid depth value.".format(value)) + raise ValidationError("'{}' is not a valid depth value.".format(value)) # lint-amnesty, pylint: disable=raise-missing-from def clean_requested_fields(self): """ @@ -75,7 +75,7 @@ class BlockListGetForm(Form): try: usage_key = UsageKey.from_string(usage_key) except InvalidKeyError: - raise ValidationError("'{}' is not a valid usage key.".format(str(usage_key))) + raise ValidationError("'{}' is not a valid usage key.".format(str(usage_key))) # lint-amnesty, pylint: disable=raise-missing-from return usage_key.replace(course_key=modulestore().fill_in_run(usage_key.course_key)) @@ -83,7 +83,7 @@ class BlockListGetForm(Form): """ Return cleaned data, including additional requested fields. """ - cleaned_data = super(BlockListGetForm, self).clean() + cleaned_data = super(BlockListGetForm, self).clean() # lint-amnesty, pylint: disable=super-with-arguments # Add additional requested_fields that are specified as separate # parameters, if they were requested. @@ -224,7 +224,7 @@ class BlockListGetForm(Form): try: return User.objects.get(username=requested_username) except User.DoesNotExist: - raise Http404( + raise Http404( # lint-amnesty, pylint: disable=raise-missing-from "Requested user '{requested_username}' does not exist.".format( requested_username=requested_username, ) diff --git a/lms/djangoapps/course_api/blocks/permissions.py b/lms/djangoapps/course_api/blocks/permissions.py index 971438adbe..d04989f632 100644 --- a/lms/djangoapps/course_api/blocks/permissions.py +++ b/lms/djangoapps/course_api/blocks/permissions.py @@ -1,7 +1,7 @@ """ Encapsulates permissions checks for Course Blocks API """ -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from opaque_keys.edx.keys import CourseKey from lms.djangoapps.courseware.access import has_access @@ -9,7 +9,7 @@ from lms.djangoapps.courseware.access_response import AccessResponse from lms.djangoapps.courseware.access_utils import ACCESS_DENIED, ACCESS_GRANTED, check_public_access from lms.djangoapps.courseware.exceptions import CourseRunNotFound from lms.djangoapps.courseware.courses import get_course -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseStaffRole from xmodule.course_module import COURSE_VISIBILITY_PUBLIC diff --git a/lms/djangoapps/course_api/blocks/serializers.py b/lms/djangoapps/course_api/blocks/serializers.py index ce570f28a1..abb4cfa291 100644 --- a/lms/djangoapps/course_api/blocks/serializers.py +++ b/lms/djangoapps/course_api/blocks/serializers.py @@ -128,7 +128,7 @@ class BlockSerializer(serializers.Serializer): # pylint: disable=abstract-metho return value if (value is not None) else default - def to_representation(self, block_key): + def to_representation(self, block_key): # lint-amnesty, pylint: disable=arguments-differ """ Return a serializable representation of the requested block """ diff --git a/lms/djangoapps/course_api/blocks/tests/test_api.py b/lms/djangoapps/course_api/blocks/tests/test_api.py index 65f7097cad..71ce999611 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_api.py +++ b/lms/djangoapps/course_api/blocks/tests/test_api.py @@ -39,7 +39,7 @@ class TestGetBlocks(SharedModuleStoreTestCase): cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test) def setUp(self): - super(TestGetBlocks, self).setUp() + super(TestGetBlocks, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.request = RequestFactory().get("/dummy") self.request.user = self.user @@ -139,7 +139,7 @@ class TestGetBlocksMobileHack(SharedModuleStoreTestCase): ) def setUp(self): - super(TestGetBlocksMobileHack, self).setUp() + super(TestGetBlocksMobileHack, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.request = RequestFactory().get("/dummy") self.request.user = self.user @@ -193,7 +193,7 @@ class TestGetBlocksQueryCountsBase(SharedModuleStoreTestCase): ENABLED_SIGNALS = ['course_published'] def setUp(self): - super(TestGetBlocksQueryCountsBase, self).setUp() + super(TestGetBlocksQueryCountsBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.request = RequestFactory().get("/dummy") diff --git a/lms/djangoapps/course_api/blocks/tests/test_forms.py b/lms/djangoapps/course_api/blocks/tests/test_forms.py index 47d23c8342..abcafb216b 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_forms.py +++ b/lms/djangoapps/course_api/blocks/tests/test_forms.py @@ -34,7 +34,7 @@ class TestBlockListGetForm(FormTestMixin, SharedModuleStoreTestCase): cls.course = CourseFactory.create() def setUp(self): - super(TestBlockListGetForm, self).setUp() + super(TestBlockListGetForm, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.student = UserFactory.create() self.student2 = UserFactory.create() diff --git a/lms/djangoapps/course_api/blocks/tests/test_serializers.py b/lms/djangoapps/course_api/blocks/tests/test_serializers.py index f0a28fbce9..bbe6e77784 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_serializers.py +++ b/lms/djangoapps/course_api/blocks/tests/test_serializers.py @@ -37,7 +37,7 @@ class TestBlockSerializerBase(SharedModuleStoreTestCase): cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test) def setUp(self): - super(TestBlockSerializerBase, self).setUp() + super(TestBlockSerializerBase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() diff --git a/lms/djangoapps/course_api/blocks/tests/test_views.py b/lms/djangoapps/course_api/blocks/tests/test_views.py index f3667a20e2..2168577659 100644 --- a/lms/djangoapps/course_api/blocks/tests/test_views.py +++ b/lms/djangoapps/course_api/blocks/tests/test_views.py @@ -48,7 +48,7 @@ class TestBlocksView(SharedModuleStoreTestCase): ) def setUp(self): - super(TestBlocksView, self).setUp() + super(TestBlocksView, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # create and enroll user in the toy course self.user = UserFactory.create() @@ -402,7 +402,7 @@ class TestBlocksInCourseView(TestBlocksView, CompletionWaffleTestMixin): # pyli """ def setUp(self): - super(TestBlocksInCourseView, self).setUp() + super(TestBlocksInCourseView, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.url = reverse('blocks_in_course') self.query_params['course_id'] = str(self.course_key) self.override_waffle_switch(True) diff --git a/lms/djangoapps/course_api/blocks/transformers/milestones.py b/lms/djangoapps/course_api/blocks/transformers/milestones.py index 218913ca6c..fc4047be48 100644 --- a/lms/djangoapps/course_api/blocks/transformers/milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/milestones.py @@ -21,7 +21,7 @@ class MilestonesAndSpecialExamsTransformer(BlockStructureTransformer): """ A transformer that handles both milestones and special (timed) exams. - It includes or excludes all unfulfilled milestones from the student view based on the value of `include_gated_sections`. + It includes or excludes all unfulfilled milestones from the student view based on the value of `include_gated_sections`. # lint-amnesty, pylint: disable=line-too-long An entrance exam is considered a milestone, and is not considered a "special exam". @@ -155,13 +155,13 @@ class MilestonesAndSpecialExamsTransformer(BlockStructureTransformer): if user_can_skip_entrance_exam: # remove the entrance exam from required content - entrance_exam_id = block_structure.get_xblock_field(block_structure.root_block_usage_key, 'entrance_exam_id') + entrance_exam_id = block_structure.get_xblock_field(block_structure.root_block_usage_key, 'entrance_exam_id') # lint-amnesty, pylint: disable=line-too-long required_content = [content for content in required_content if not content == entrance_exam_id] return required_content @staticmethod - def gated_by_required_content(block_key, block_structure, required_content): + def gated_by_required_content(block_key, block_structure, required_content): # lint-amnesty, pylint: disable=unused-argument """ Returns True if the current block associated with the block_key should be gated by the given required_content. Returns False otherwise. diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py index 0bddc35311..913cd5d1b1 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_completion.py @@ -36,7 +36,7 @@ class StubCompletableXBlock(XBlock, CompletableXBlockMixin): XBlock to test behaviour of BlockCompletionTransformer when transforming completable XBlock. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class BlockCompletionTransformerTestCase(TransformerRegistryTestMixin, CompletionWaffleTestMixin, ModuleStoreTestCase): @@ -47,7 +47,7 @@ class BlockCompletionTransformerTestCase(TransformerRegistryTestMixin, Completio COMPLETION_TEST_VALUE = 0.4 def setUp(self): - super(BlockCompletionTransformerTestCase, self).setUp() + super(BlockCompletionTransformerTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create(password='test') # Set ENABLE_COMPLETION_TRACKING waffle switch to True self.override_waffle_switch(True) diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py index 2ee36a7b9c..d248f93315 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_block_counts.py @@ -18,7 +18,7 @@ class TestBlockCountsTransformer(ModuleStoreTestCase): """ def setUp(self): - super(TestBlockCountsTransformer, self).setUp() + super(TestBlockCountsTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = SampleCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key(self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store) diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py index e820cdd18d..331e7e021f 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_extra_fields.py @@ -30,7 +30,7 @@ class TestExtraFieldsTransformer(ModuleStoreTestCase): } def setUp(self): - super(TestExtraFieldsTransformer, self).setUp() + super(TestExtraFieldsTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = SampleCourseFactory.create( other_course_settings=self.OTHER_COURSE_SETTINGS_DEFAULT diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py index c44ccd9863..99fccbbe68 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py @@ -30,7 +30,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM """ Setup course structure and create user for split test transformer test. """ - super(MilestonesTransformerTestCase, self).setUp() + super(MilestonesTransformerTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Build course. self.course_hierarchy = self.get_course_hierarchy() @@ -198,8 +198,8 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM self.course.enable_subsection_gating = True self.setup_gated_section(self.blocks['H'], self.blocks['A']) expected_blocks = ( - 'course', 'A', 'B', 'C', 'ProctoredExam', 'D', 'E', 'PracticeExam', 'F', 'G', 'TimedExam', 'J', 'K', 'H', 'I' - ) + 'course', 'A', 'B', 'C', 'ProctoredExam', 'D', 'E', 'PracticeExam', 'F', 'G', 'TimedExam', 'J', 'K', 'H', + 'I') # lint-amnesty, pylint: disable=line-too-long self.get_blocks_and_check_against_expected(self.user, expected_blocks) # clear the request cache to simulate a new request self.clear_caches() diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py index 3a88fda5d6..0b040e62e6 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py @@ -20,7 +20,7 @@ class TestStudentViewTransformer(ModuleStoreTestCase): """ def setUp(self): - super(TestStudentViewTransformer, self).setUp() + super(TestStudentViewTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = ToyCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key(self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store) diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py index 70536f161e..6d59d03dd9 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_video_urls.py @@ -20,7 +20,7 @@ class TestVideoBlockURLTransformer(ModuleStoreTestCase): """ def setUp(self): - super(TestVideoBlockURLTransformer, self).setUp() + super(TestVideoBlockURLTransformer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = ToyCourseFactory.create().id self.course_usage_key = self.store.make_course_usage_key(self.course_key) self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store) diff --git a/lms/djangoapps/course_api/blocks/views.py b/lms/djangoapps/course_api/blocks/views.py index 34e054a2e9..7fc7b3d844 100644 --- a/lms/djangoapps/course_api/blocks/views.py +++ b/lms/djangoapps/course_api/blocks/views.py @@ -238,7 +238,7 @@ class BlocksView(DeveloperErrorViewMixin, ListAPIView): patch_response_headers(response) return response except ItemNotFoundError as exception: - raise Http404(u"Block not found: {}".format(text_type(exception))) + raise Http404(u"Block not found: {}".format(text_type(exception))) # lint-amnesty, pylint: disable=raise-missing-from @view_auth_classes(is_authenticated=False) @@ -301,9 +301,9 @@ class BlocksInCourseView(BlocksView): course_key = CourseKey.from_string(course_key_string) course_usage_key = modulestore().make_course_usage_key(course_key) except InvalidKeyError: - raise ValidationError(u"'{}' is not a valid course key.".format(six.text_type(course_key_string))) + raise ValidationError(u"'{}' is not a valid course key.".format(six.text_type(course_key_string))) # lint-amnesty, pylint: disable=raise-missing-from response = super().list(request, course_usage_key, - hide_access_denials=hide_access_denials) + hide_access_denials=hide_access_denials) # lint-amnesty, pylint: disable=super-with-arguments if 'completion' not in request.query_params.getlist('requested_fields', ''): return response @@ -353,3 +353,4 @@ def recurse_mark_complete(block_id, blocks): completable_blocks = [blocks[child_block_id] for child_block_id in child_blocks if blocks[child_block_id].get('type') != 'discussion'] block['completion'] = int(all(child.get('completion') == 1 for child in completable_blocks)) + diff --git a/lms/djangoapps/course_api/forms.py b/lms/djangoapps/course_api/forms.py index 3340dba413..ae30938ca4 100644 --- a/lms/djangoapps/course_api/forms.py +++ b/lms/djangoapps/course_api/forms.py @@ -43,7 +43,7 @@ class CourseDetailGetForm(UsernameValidatorMixin, Form): try: return CourseKey.from_string(course_key_string) except InvalidKeyError: - raise ValidationError(u"'{}' is not a valid course key.".format(six.text_type(course_key_string))) + raise ValidationError(u"'{}' is not a valid course key.".format(six.text_type(course_key_string))) # lint-amnesty, pylint: disable=raise-missing-from class CourseListGetForm(UsernameValidatorMixin, Form): @@ -65,7 +65,7 @@ class CourseListGetForm(UsernameValidatorMixin, Form): """ Return cleaned data, including additional filters. """ - cleaned_data = super(CourseListGetForm, self).clean() + cleaned_data = super(CourseListGetForm, self).clean() # lint-amnesty, pylint: disable=super-with-arguments # create a filter for all supported filter fields filter_ = dict() diff --git a/lms/djangoapps/course_api/serializers.py b/lms/djangoapps/course_api/serializers.py index 1f5a8ab4c6..12c734c705 100644 --- a/lms/djangoapps/course_api/serializers.py +++ b/lms/djangoapps/course_api/serializers.py @@ -4,14 +4,14 @@ Course API Serializers. Representing course catalog data from edx_django_utils import monitoring as monitoring_utils -import six.moves.urllib.error -import six.moves.urllib.parse -import six.moves.urllib.request +import six.moves.urllib.error # lint-amnesty, pylint: disable=wrong-import-order +import six.moves.urllib.parse # lint-amnesty, pylint: disable=wrong-import-order +import six.moves.urllib.request # lint-amnesty, pylint: disable=wrong-import-order from django.urls import reverse from rest_framework import serializers from openedx.core.djangoapps.models.course_details import CourseDetails -from openedx.core.djangoapps.content.course_overviews.models import CourseOverview +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview # lint-amnesty, pylint: disable=unused-import from openedx.core.lib.api.fields import AbsoluteURLField @@ -21,7 +21,7 @@ class _MediaSerializer(serializers.Serializer): # pylint: disable=abstract-meth """ def __init__(self, uri_attribute, *args, **kwargs): - super(_MediaSerializer, self).__init__(*args, **kwargs) + super(_MediaSerializer, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments self.uri_attribute = uri_attribute uri = serializers.SerializerMethodField(source='*') @@ -41,7 +41,7 @@ class _AbsolutMediaSerializer(_MediaSerializer): # pylint: disable=abstract-met def __call__(self, serializer_field): self.context = serializer_field.context - return super(self).__call__(serializer_field) + return super(self).__call__(serializer_field) # lint-amnesty, pylint: disable=bad-super-call uri_absolute = serializers.SerializerMethodField(source="*") @@ -62,7 +62,7 @@ class _AbsolutMediaSerializer(_MediaSerializer): # pylint: disable=abstract-met # In order to use the AbsoluteURLField to have the same # behaviour what ImageSerializer provides, we need to set # the request for the field - field._context = {"request": self.context.get("request")} + field._context = {"request": self.context.get("request")} # lint-amnesty, pylint: disable=protected-access return field.to_representation(cdn_applied_uri) diff --git a/lms/djangoapps/course_api/tests/test_api.py b/lms/djangoapps/course_api/tests/test_api.py index dda51d7e7c..3d14ffa07f 100644 --- a/lms/djangoapps/course_api/tests/test_api.py +++ b/lms/djangoapps/course_api/tests/test_api.py @@ -164,7 +164,7 @@ class TestGetCourseListMultipleCourses(CourseListTestMixin, ModuleStoreTestCase) ENABLED_SIGNALS = ['course_published'] def setUp(self): - super(TestGetCourseListMultipleCourses, self).setUp() + super(TestGetCourseListMultipleCourses, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = self.create_course(mobile_available=False) self.staff_user = self.create_user("staff", is_staff=True) self.honor_user = self.create_user("honor", is_staff=False) diff --git a/lms/djangoapps/course_api/tests/test_forms.py b/lms/djangoapps/course_api/tests/test_forms.py index 100d2de23f..2fce9e2805 100644 --- a/lms/djangoapps/course_api/tests/test_forms.py +++ b/lms/djangoapps/course_api/tests/test_forms.py @@ -48,7 +48,7 @@ class TestCourseListGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStoreT cls.course = CourseFactory.create() def setUp(self): - super(TestCourseListGetForm, self).setUp() + super(TestCourseListGetForm, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.student = UserFactory.create() self.set_up_data(self.student) @@ -100,7 +100,7 @@ class TestCourseListGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStoreT self.assert_valid(self.cleaned_data) -class TestCourseIdListGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStoreTestCase): +class TestCourseIdListGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring FORM_CLASS = CourseIdListGetForm @classmethod @@ -110,7 +110,7 @@ class TestCourseIdListGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStor cls.course = CourseFactory.create() def setUp(self): - super(TestCourseIdListGetForm, self).setUp() + super(TestCourseIdListGetForm, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.student = UserFactory.create() self.set_up_data(self.student) @@ -149,7 +149,7 @@ class TestCourseDetailGetForm(FormTestMixin, UsernameTestMixin, SharedModuleStor cls.course = CourseFactory.create() def setUp(self): - super(TestCourseDetailGetForm, self).setUp() + super(TestCourseDetailGetForm, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.student = UserFactory.create() self.set_up_data(self.student) diff --git a/lms/djangoapps/course_api/tests/test_serializers.py b/lms/djangoapps/course_api/tests/test_serializers.py index d6ea499998..1077764ec9 100644 --- a/lms/djangoapps/course_api/tests/test_serializers.py +++ b/lms/djangoapps/course_api/tests/test_serializers.py @@ -34,7 +34,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): ENABLED_SIGNALS = ['course_published'] def setUp(self): - super(TestCourseSerializer, self).setUp() + super(TestCourseSerializer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.staff_user = self.create_user('staff', is_staff=True) self.honor_user = self.create_user('honor', is_staff=False) self.request_factory = APIRequestFactory() @@ -146,7 +146,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): self.assertEqual(result['pacing'], expected_pacing) -class TestCourseDetailSerializer(TestCourseSerializer): +class TestCourseDetailSerializer(TestCourseSerializer): # lint-amnesty, pylint: disable=test-inherits-tests """ Test CourseDetailSerializer by rerunning all the tests in TestCourseSerializer, but with the @@ -158,7 +158,7 @@ class TestCourseDetailSerializer(TestCourseSerializer): serializer_class = CourseDetailSerializer def setUp(self): - super(TestCourseDetailSerializer, self).setUp() + super(TestCourseDetailSerializer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # update the expected_data to include the 'overview' data. about_descriptor = XBlock.load_class('about') @@ -166,7 +166,7 @@ class TestCourseDetailSerializer(TestCourseSerializer): self.expected_data['overview'] = overview_template.get('data') -class TestCourseKeySerializer(TestCase): +class TestCourseKeySerializer(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring def test_course_key_serializer(self): course_key = CourseLocator(org='org', course='course', run='2020_Q3') diff --git a/lms/djangoapps/course_api/tests/test_views.py b/lms/djangoapps/course_api/tests/test_views.py index b38927f4dd..f3fdf68216 100644 --- a/lms/djangoapps/course_api/tests/test_views.py +++ b/lms/djangoapps/course_api/tests/test_views.py @@ -22,7 +22,7 @@ from waffle.testutils import override_switch from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.course_modes.tests.factories import CourseModeFactory -from opaque_keys.edx.locator import LibraryLocator +from opaque_keys.edx.locator import LibraryLocator # lint-amnesty, pylint: disable=wrong-import-order from openedx.core.lib.api.view_utils import LazySequence from openedx.features.content_type_gating.models import ContentTypeGatingConfig from openedx.features.course_duration_limits.models import CourseDurationLimitConfig @@ -160,7 +160,7 @@ class CourseListViewTestCaseMultipleCourses(CourseApiTestViewMixin, ModuleStoreT ENABLED_SIGNALS = ['course_published'] def setUp(self): - super(CourseListViewTestCaseMultipleCourses, self).setUp() + super(CourseListViewTestCaseMultipleCourses, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = self.create_course(mobile_available=False) self.url = reverse('course-list') self.staff_user = self.create_user(username='staff', is_staff=True) @@ -298,7 +298,7 @@ class CourseListSearchViewTest(CourseApiTestViewMixin, ModuleStoreTestCase, Sear ENABLED_CACHES = ModuleStoreTestCase.ENABLED_CACHES + ['configuration'] def setUp(self): - super(CourseListSearchViewTest, self).setUp() + super(CourseListSearchViewTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments DemoCourse.reset_count() self.searcher.destroy() @@ -422,7 +422,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): ENABLED_SIGNALS = ['course_published'] def setUp(self): - super(CourseIdListViewTestCase, self).setUp() + super(CourseIdListViewTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = self.create_course() self.url = reverse('course-id-list') self.staff_user = self.create_user(username='staff', is_staff=True) @@ -535,7 +535,7 @@ class CourseIdListViewTestCase(CourseApiTestViewMixin, ModuleStoreTestCase): self.assertTrue(filtered_response.data['results'][0].startswith(self.course.org)) -class LazyPageNumberPaginationTestCase(TestCase): +class LazyPageNumberPaginationTestCase(TestCase): # lint-amnesty, pylint: disable=missing-class-docstring def test_lazy_page_number_pagination(self): number_sequence = range(20) diff --git a/lms/djangoapps/course_api/views.py b/lms/djangoapps/course_api/views.py index 94eb84508a..03fe46355f 100644 --- a/lms/djangoapps/course_api/views.py +++ b/lms/djangoapps/course_api/views.py @@ -138,7 +138,7 @@ class CourseListUserThrottle(UserRateThrottle): 'staff': '40/minute', } - def check_for_switches(self): + def check_for_switches(self): # lint-amnesty, pylint: disable=missing-function-docstring if USE_RATE_LIMIT_2_FOR_COURSE_LIST_API.is_enabled(): self.THROTTLE_RATES = { 'user': '2/minute', @@ -159,7 +159,7 @@ class CourseListUserThrottle(UserRateThrottle): self.rate = self.get_rate() self.num_requests, self.duration = self.parse_rate(self.rate) - return super(CourseListUserThrottle, self).allow_request(request, view) + return super(CourseListUserThrottle, self).allow_request(request, view) # lint-amnesty, pylint: disable=super-with-arguments class LazyPageNumberPagination(NamespacedPageNumberPagination): @@ -191,9 +191,9 @@ class LazyPageNumberPagination(NamespacedPageNumberPagination): page_number=page_number, message=str(exc) ) self.page.number = self.page.paginator.num_pages - raise NotFound(msg) + raise NotFound(msg) # lint-amnesty, pylint: disable=raise-missing-from - return super(LazyPageNumberPagination, self).get_paginated_response(data) + return super(LazyPageNumberPagination, self).get_paginated_response(data) # lint-amnesty, pylint: disable=super-with-arguments @function_trace('pagination_paginate_queryset') def paginate_queryset(self, queryset, request, view=None): @@ -220,19 +220,19 @@ class LazyPageNumberPagination(NamespacedPageNumberPagination): with function_trace('pagination_paginate_queryset_get_page'): try: - self.page = paginator.page(page_number) + self.page = paginator.page(page_number) # lint-amnesty, pylint: disable=attribute-defined-outside-init except InvalidPage as exc: msg = self.invalid_page_message.format( page_number=page_number, message=str(exc) ) - raise NotFound(msg) + raise NotFound(msg) # lint-amnesty, pylint: disable=raise-missing-from with function_trace('pagination_paginate_queryset_get_num_pages'): if paginator.num_pages > 1 and self.template is not None: # The browsable API should display pagination controls. self.display_page_controls = True - self.request = request + self.request = request # lint-amnesty, pylint: disable=attribute-defined-outside-init with function_trace('pagination_paginate_queryset_listify_page'): page_list = list(self.page) @@ -347,7 +347,7 @@ class CourseIdListUserThrottle(UserRateThrottle): self.rate = self.get_rate() self.num_requests, self.duration = self.parse_rate(self.rate) - return super(CourseIdListUserThrottle, self).allow_request(request, view) + return super(CourseIdListUserThrottle, self).allow_request(request, view) # lint-amnesty, pylint: disable=super-with-arguments @view_auth_classes() @@ -434,7 +434,7 @@ class CourseIdListView(DeveloperErrorViewMixin, ListAPIView): This should be called once per GET request. """ - return super(CourseIdListView, self).paginate_queryset(*args, **kwargs) + return super(CourseIdListView, self).paginate_queryset(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments @function_trace('get_paginated_response') def get_paginated_response(self, *args, **kwargs): @@ -446,7 +446,7 @@ class CourseIdListView(DeveloperErrorViewMixin, ListAPIView): means two GET requests and one function call per request. Otherwise, if the whole response fits in one page, this function never gets called. """ - return super(CourseIdListView, self).get_paginated_response(*args, **kwargs) + return super(CourseIdListView, self).get_paginated_response(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments @function_trace('filter_queryset') def filter_queryset(self, *args, **kwargs): @@ -456,7 +456,7 @@ class CourseIdListView(DeveloperErrorViewMixin, ListAPIView): This should be called once per GET request. """ - return super(CourseIdListView, self).filter_queryset(*args, **kwargs) + return super(CourseIdListView, self).filter_queryset(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments @function_trace('get_serializer') def get_serializer(self, *args, **kwargs): @@ -466,4 +466,4 @@ class CourseIdListView(DeveloperErrorViewMixin, ListAPIView): This should be called once per GET request. """ - return super(CourseIdListView, self).get_serializer(*args, **kwargs) + return super(CourseIdListView, self).get_serializer(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments From 959aed9841894e55b527d3ae933389b4b442e4db Mon Sep 17 00:00:00 2001 From: Jawayria Date: Thu, 4 Feb 2021 14:07:47 +0500 Subject: [PATCH 2/2] Resolved pep8 issues --- .../course_api/blocks/transformers/tests/test_milestones.py | 2 +- lms/djangoapps/course_api/blocks/views.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py index 99fccbbe68..445065bd05 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_milestones.py @@ -199,7 +199,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM self.setup_gated_section(self.blocks['H'], self.blocks['A']) expected_blocks = ( 'course', 'A', 'B', 'C', 'ProctoredExam', 'D', 'E', 'PracticeExam', 'F', 'G', 'TimedExam', 'J', 'K', 'H', - 'I') # lint-amnesty, pylint: disable=line-too-long + 'I') # lint-amnesty, pylint: disable=line-too-long self.get_blocks_and_check_against_expected(self.user, expected_blocks) # clear the request cache to simulate a new request self.clear_caches() diff --git a/lms/djangoapps/course_api/blocks/views.py b/lms/djangoapps/course_api/blocks/views.py index 7fc7b3d844..94fb050b85 100644 --- a/lms/djangoapps/course_api/blocks/views.py +++ b/lms/djangoapps/course_api/blocks/views.py @@ -353,4 +353,3 @@ def recurse_mark_complete(block_id, blocks): completable_blocks = [blocks[child_block_id] for child_block_id in child_blocks if blocks[child_block_id].get('type') != 'discussion'] block['completion'] = int(all(child.get('completion') == 1 for child in completable_blocks)) -