From 59f41365850479ed9ccaaba28cc9f8caf8b85186 Mon Sep 17 00:00:00 2001 From: "M. Zulqarnain" <muhammad.zulqarnain@arbisoft.com> Date: Wed, 3 Feb 2021 18:14:49 +0500 Subject: [PATCH] BOM-2316 : Pylint amnesty in openedx apps (#26340) * lint amnesty in openedx apps --- openedx/core/djangoapps/cache_toolbox/__init__.py | 2 +- .../core/djangoapps/cache_toolbox/middleware.py | 8 ++++---- .../cache_toolbox/templatetags/cache_toolbox.py | 2 +- .../cache_toolbox/tests/test_middleware.py | 4 ++-- openedx/core/djangoapps/catalog/__init__.py | 1 + openedx/core/djangoapps/catalog/cache.py | 1 + .../catalog/management/commands/cache_programs.py | 8 ++++---- .../commands/create_catalog_integrations.py | 2 +- .../management/commands/sync_course_runs.py | 2 +- .../commands/tests/test_cache_programs.py | 2 +- .../tests/test_create_catalog_integrations.py | 2 +- .../commands/tests/test_sync_course_runs.py | 6 +++--- .../core/djangoapps/catalog/tests/test_utils.py | 14 +++++++------- openedx/core/djangoapps/catalog/utils.py | 6 +++--- openedx/core/djangoapps/catalog/views.py | 3 +-- openedx/core/djangoapps/ccxcon/__init__.py | 2 +- openedx/core/djangoapps/ccxcon/api.py | 4 ++-- openedx/core/djangoapps/ccxcon/apps.py | 4 ++-- openedx/core/djangoapps/ccxcon/tasks.py | 2 +- openedx/core/djangoapps/ccxcon/tests/test_api.py | 4 ++-- openedx/core/djangoapps/certificates/api.py | 4 ++-- 21 files changed, 42 insertions(+), 41 deletions(-) diff --git a/openedx/core/djangoapps/cache_toolbox/__init__.py b/openedx/core/djangoapps/cache_toolbox/__init__.py index f41654ad433..827e61813c2 100644 --- a/openedx/core/djangoapps/cache_toolbox/__init__.py +++ b/openedx/core/djangoapps/cache_toolbox/__init__.py @@ -1,4 +1,4 @@ -""" +""" # lint-amnesty, pylint: disable=django-not-configured :mod:`cache_toolbox` --- Non-magical object caching tools for Django ==================================================================== diff --git a/openedx/core/djangoapps/cache_toolbox/middleware.py b/openedx/core/djangoapps/cache_toolbox/middleware.py index 13b113f4347..3f83690d753 100644 --- a/openedx/core/djangoapps/cache_toolbox/middleware.py +++ b/openedx/core/djangoapps/cache_toolbox/middleware.py @@ -84,7 +84,7 @@ from logging import getLogger from django.conf import settings from django.contrib.auth import HASH_SESSION_KEY from django.contrib.auth.middleware import AuthenticationMiddleware -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.utils.crypto import constant_time_compare from django.utils.deprecation import MiddlewareMixin @@ -101,13 +101,13 @@ class CacheBackedAuthenticationMiddleware(AuthenticationMiddleware, MiddlewareMi """ def __init__(self, *args, **kwargs): cache_model(User) - super(CacheBackedAuthenticationMiddleware, self).__init__(*args, **kwargs) + super(CacheBackedAuthenticationMiddleware, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def process_request(self, request): try: # Try and construct a User instance from data stored in the cache session_user_id = SafeSessionMiddleware.get_user_id_from_session(request) - request.user = User.get_cached(session_user_id) + request.user = User.get_cached(session_user_id) # lint-amnesty, pylint: disable=no-member if request.user.id != session_user_id: log.error( u"CacheBackedAuthenticationMiddleware cached user '%s' does not match requested user '%s'.", @@ -119,7 +119,7 @@ class CacheBackedAuthenticationMiddleware(AuthenticationMiddleware, MiddlewareMi self._verify_session_auth(request) except: # pylint: disable=bare-except # Fallback to constructing the User from the database. - super(CacheBackedAuthenticationMiddleware, self).process_request(request) + super(CacheBackedAuthenticationMiddleware, self).process_request(request) # lint-amnesty, pylint: disable=super-with-arguments def _verify_session_auth(self, request): """ diff --git a/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py b/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py index 116e1509883..0d850dd3d71 100644 --- a/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py +++ b/openedx/core/djangoapps/cache_toolbox/templatetags/cache_toolbox.py @@ -7,7 +7,7 @@ automatically caching template fragments. from django import template from django.core.cache import cache from django.template import Node, TemplateSyntaxError, Variable -from django.template import resolve_variable +from django.template import resolve_variable # lint-amnesty, pylint: disable=no-name-in-module register = template.Library() # pylint: disable=invalid-name diff --git a/openedx/core/djangoapps/cache_toolbox/tests/test_middleware.py b/openedx/core/djangoapps/cache_toolbox/tests/test_middleware.py index ee4de81e827..21179d96d9e 100644 --- a/openedx/core/djangoapps/cache_toolbox/tests/test_middleware.py +++ b/openedx/core/djangoapps/cache_toolbox/tests/test_middleware.py @@ -2,7 +2,7 @@ from django.conf import settings -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.urls import reverse from django.test import TestCase from mock import patch @@ -15,7 +15,7 @@ class CachedAuthMiddlewareTestCase(TestCase): """Tests for CacheBackedAuthenticationMiddleware class.""" def setUp(self): - super(CachedAuthMiddlewareTestCase, self).setUp() + super(CachedAuthMiddlewareTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments password = 'test-password' self.user = UserFactory(password=password) self.client.login(username=self.user.username, password=password) diff --git a/openedx/core/djangoapps/catalog/__init__.py b/openedx/core/djangoapps/catalog/__init__.py index 94f0a53f551..f9df367bee8 100644 --- a/openedx/core/djangoapps/catalog/__init__.py +++ b/openedx/core/djangoapps/catalog/__init__.py @@ -1 +1,2 @@ +# lint-amnesty, pylint: disable=django-not-configured, missing-module-docstring default_app_config = 'openedx.core.djangoapps.catalog.apps.CatalogConfig' diff --git a/openedx/core/djangoapps/catalog/cache.py b/openedx/core/djangoapps/catalog/cache.py index 8f3a302870f..044ce074203 100644 --- a/openedx/core/djangoapps/catalog/cache.py +++ b/openedx/core/djangoapps/catalog/cache.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring # Template used to create cache keys for individual programs. PROGRAM_CACHE_KEY_TPL = 'program-{uuid}' diff --git a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py index b16796fa068..75b8705a201 100644 --- a/openedx/core/djangoapps/catalog/management/commands/cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/cache_programs.py @@ -44,8 +44,8 @@ class Command(BaseCommand): """ help = "Rebuild the LMS' cache of program data." - # pylint: disable=unicode-format-string - def handle(self, *args, **options): + # lint-amnesty, pylint: disable=bad-option-value, unicode-format-string + def handle(self, *args, **options): # lint-amnesty, pylint: disable=too-many-statements failure = False logger.info('populate-multitenant-programs switch is ON') @@ -135,7 +135,7 @@ class Command(BaseCommand): if failure: sys.exit(1) - def get_site_program_uuids(self, client, site): + def get_site_program_uuids(self, client, site): # lint-amnesty, pylint: disable=missing-function-docstring failure = False uuids = [] try: @@ -157,7 +157,7 @@ class Command(BaseCommand): )) return uuids, failure - def fetch_program_details(self, client, uuids): + def fetch_program_details(self, client, uuids): # lint-amnesty, pylint: disable=missing-function-docstring programs = {} failure = False for uuid in uuids: diff --git a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py index 5650e267a74..2a9ced1bb27 100644 --- a/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/create_catalog_integrations.py @@ -66,7 +66,7 @@ class Command(BaseCommand): page_size=page_size ) except Exception as err: - raise CommandError(u'Error creating CatalogIntegration: {}'.format(err)) + raise CommandError(u'Error creating CatalogIntegration: {}'.format(err)) # lint-amnesty, pylint: disable=raise-missing-from self.stdout.write(self.style.SUCCESS( u'Successfully created CatalogIntegration enabled={} url={} service_username={}').format( diff --git a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py index 1ddb9d86caa..f503d192df2 100644 --- a/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/sync_course_runs.py @@ -10,7 +10,7 @@ from opaque_keys.edx.keys import CourseKey from openedx.core.djangoapps.catalog.utils import get_course_runs from openedx.core.djangoapps.content.course_overviews.models import CourseOverview -import six +import six # lint-amnesty, pylint: disable=wrong-import-order log = logging.getLogger(__name__) diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py index 93e1d3339b5..e7722b1b67c 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_cache_programs.py @@ -35,7 +35,7 @@ class TestCachePrograms(CatalogIntegrationMixin, CacheIsolationTestCase, SiteMix ENABLED_CACHES = ['default'] def setUp(self): - super(TestCachePrograms, self).setUp() + super(TestCachePrograms, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments httpretty.httpretty.reset() diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py index a7dbe0a8d75..c58c05e29da 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_create_catalog_integrations.py @@ -2,7 +2,7 @@ Test cases for catalog_integrations command. """ -from django.test import TestCase +from django.test import TestCase # lint-amnesty, pylint: disable=unused-import from django.core.management import call_command, CommandError from openedx.core.djangolib.testing.utils import CacheIsolationTestCase diff --git a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py index c6b5d0114e4..d4e891602c8 100644 --- a/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py +++ b/openedx/core/djangoapps/catalog/management/commands/tests/test_sync_course_runs.py @@ -12,7 +12,7 @@ from openedx.core.djangoapps.catalog.management.commands.sync_course_runs import from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -import six +import six # lint-amnesty, pylint: disable=wrong-import-order COMMAND_MODULE = 'openedx.core.djangoapps.catalog.management.commands.sync_course_runs' @@ -24,7 +24,7 @@ class TestSyncCourseRunsCommand(ModuleStoreTestCase): Test for the sync course runs management command. """ def setUp(self): - super(TestSyncCourseRunsCommand, self).setUp() + super(TestSyncCourseRunsCommand, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # create mongo course self.course = CourseFactory.create() # load this course into course overview @@ -57,7 +57,7 @@ class TestSyncCourseRunsCommand(ModuleStoreTestCase): # course overview value matches catalog value self.assertEqual( updated_course_overview_value, - self.catalog_course_run.get(catalog_field_name), + self.catalog_course_run.get(catalog_field_name), # lint-amnesty, pylint: disable=no-member ) # new value doesn't match old value self.assertNotEqual( diff --git a/openedx/core/djangoapps/catalog/tests/test_utils.py b/openedx/core/djangoapps/catalog/tests/test_utils.py index c2f2c10d889..3cbfd5d0188 100644 --- a/openedx/core/djangoapps/catalog/tests/test_utils.py +++ b/openedx/core/djangoapps/catalog/tests/test_utils.py @@ -73,7 +73,7 @@ class TestGetPrograms(CacheIsolationTestCase): ENABLED_CACHES = ['default'] def setUp(self): - super(TestGetPrograms, self).setUp() + super(TestGetPrograms, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.site = SiteFactory() def test_get_many(self, mock_warning, mock_info): @@ -272,7 +272,7 @@ class TestGetPathways(CacheIsolationTestCase): ENABLED_CACHES = ['default'] def setUp(self): - super(TestGetPathways, self).setUp() + super(TestGetPathways, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.site = SiteFactory() def test_get_many(self, mock_warning, mock_info): @@ -470,7 +470,7 @@ class TestGetCourseRuns(CatalogIntegrationMixin, CacheIsolationTestCase): Tests covering retrieval of course runs from the catalog service. """ def setUp(self): - super(TestGetCourseRuns, self).setUp() + super(TestGetCourseRuns, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.catalog_integration = self.create_catalog_integration(cache_ttl=1) self.user = UserFactory(username=self.catalog_integration.service_username) @@ -553,7 +553,7 @@ class TestGetCourseOwners(CatalogIntegrationMixin, TestCase): Tests covering retrieval of course runs from the catalog service. """ def setUp(self): - super(TestGetCourseOwners, self).setUp() + super(TestGetCourseOwners, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.catalog_integration = self.create_catalog_integration(cache_ttl=1) self.user = UserFactory(username=self.catalog_integration.service_username) @@ -578,7 +578,7 @@ class TestSessionEntitlement(CatalogIntegrationMixin, TestCase): Test Covering data related Entitlements. """ def setUp(self): - super(TestSessionEntitlement, self).setUp() + super(TestSessionEntitlement, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.catalog_integration = self.create_catalog_integration(cache_ttl=1) self.user = UserFactory(username=self.catalog_integration.service_username) @@ -686,7 +686,7 @@ class TestGetCourseRunDetails(CatalogIntegrationMixin, TestCase): Tests covering retrieval of information about a specific course run from the catalog service. """ def setUp(self): - super(TestGetCourseRunDetails, self).setUp() + super(TestGetCourseRunDetails, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.catalog_integration = self.create_catalog_integration(cache_ttl=1) self.user = UserFactory(username=self.catalog_integration.service_username) @@ -865,7 +865,7 @@ class TestGetProgramsByType(CacheIsolationTestCase): def setUp(self): """ Loads program data into the cache before each test function. """ - super(TestGetProgramsByType, self).setUp() + super(TestGetProgramsByType, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.init_cache() def init_cache(self): diff --git a/openedx/core/djangoapps/catalog/utils.py b/openedx/core/djangoapps/catalog/utils.py index cfeeb008dbd..6a2a746a498 100644 --- a/openedx/core/djangoapps/catalog/utils.py +++ b/openedx/core/djangoapps/catalog/utils.py @@ -15,7 +15,7 @@ from pytz import UTC from six import text_type from common.djangoapps.entitlements.utils import is_course_run_entitlement_fulfillable -from openedx.core.constants import COURSE_PUBLISHED +from openedx.core.constants import COURSE_PUBLISHED # lint-amnesty, pylint: disable=unused-import from openedx.core.djangoapps.catalog.cache import ( COURSE_PROGRAMS_CACHE_KEY_TPL, CATALOG_COURSE_PROGRAMS_CACHE_KEY_TPL, @@ -424,7 +424,7 @@ def get_course_runs(): return course_runs -def get_course_runs_for_course(course_uuid): +def get_course_runs_for_course(course_uuid): # lint-amnesty, pylint: disable=missing-function-docstring user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Course runs') if user: api = create_catalog_api_client(user) @@ -446,7 +446,7 @@ def get_course_runs_for_course(course_uuid): return [] -def get_owners_for_course(course_uuid): +def get_owners_for_course(course_uuid): # lint-amnesty, pylint: disable=missing-function-docstring user, catalog_integration = check_catalog_integration_and_get_user(error_message_field='Owners') if user: api = create_catalog_api_client(user) diff --git a/openedx/core/djangoapps/catalog/views.py b/openedx/core/djangoapps/catalog/views.py index a6c1ba37049..0e5e5ab088c 100644 --- a/openedx/core/djangoapps/catalog/views.py +++ b/openedx/core/djangoapps/catalog/views.py @@ -1,5 +1,4 @@ - - +# lint-amnesty, pylint: disable=missing-module-docstring from django.conf import settings from django.core.management import call_command from django.http import Http404, HttpResponse diff --git a/openedx/core/djangoapps/ccxcon/__init__.py b/openedx/core/djangoapps/ccxcon/__init__.py index 98a839e4691..04d742a9391 100644 --- a/openedx/core/djangoapps/ccxcon/__init__.py +++ b/openedx/core/djangoapps/ccxcon/__init__.py @@ -1,4 +1,4 @@ -""" +""" # lint-amnesty, pylint: disable=django-not-configured The ccxcon app contains the models and the APIs to interact with the `CCX Connector`, an application external to openedx that is used to interact with the CCX and their master courses. diff --git a/openedx/core/djangoapps/ccxcon/api.py b/openedx/core/djangoapps/ccxcon/api.py index 514cf122ac2..8c99b864237 100644 --- a/openedx/core/djangoapps/ccxcon/api.py +++ b/openedx/core/djangoapps/ccxcon/api.py @@ -6,7 +6,7 @@ Module containing API functions for the CCXCon import logging import six -import six.moves.urllib.parse # pylint: disable=import-error +import six.moves.urllib.parse # lint-amnesty, pylint: disable=import-error, wrong-import-order from django.core.exceptions import ValidationError from django.core.validators import URLValidator from django.http import Http404 @@ -149,7 +149,7 @@ def course_info_to_ccxcon(course_key): ) if resp.status_code >= 500: - raise CCXConnServerError(u'Server returned error Status: %s, Content: %s', resp.status_code, resp.content) + raise CCXConnServerError(u'Server returned error Status: %s, Content: %s', resp.status_code, resp.content) # lint-amnesty, pylint: disable=raising-format-tuple if resp.status_code >= 400: log.error(u"Error creating course on ccxcon. Status: %s, Content: %s", resp.status_code, resp.content) # this API performs a POST request both for POST and PATCH, but the POST returns 201 and the PATCH returns 200 diff --git a/openedx/core/djangoapps/ccxcon/apps.py b/openedx/core/djangoapps/ccxcon/apps.py index a2e07684ade..40aa4a32676 100644 --- a/openedx/core/djangoapps/ccxcon/apps.py +++ b/openedx/core/djangoapps/ccxcon/apps.py @@ -6,9 +6,9 @@ Configuration for CCX connector from django.apps import AppConfig -class CCXConnectorConfig(AppConfig): +class CCXConnectorConfig(AppConfig): # lint-amnesty, pylint: disable=missing-class-docstring name = 'openedx.core.djangoapps.ccxcon' verbose_name = "CCX Connector" def ready(self): - from . import signals + from . import signals # lint-amnesty, pylint: disable=unused-import diff --git a/openedx/core/djangoapps/ccxcon/tasks.py b/openedx/core/djangoapps/ccxcon/tasks.py index 13d137320f2..2b36c0ae7a1 100644 --- a/openedx/core/djangoapps/ccxcon/tasks.py +++ b/openedx/core/djangoapps/ccxcon/tasks.py @@ -7,7 +7,7 @@ from celery.task import task from celery.utils.log import get_task_logger from edx_django_utils.monitoring import set_code_owner_attribute from opaque_keys.edx.keys import CourseKey -from requests.exceptions import ConnectionError, HTTPError, RequestException, TooManyRedirects +from requests.exceptions import ConnectionError, HTTPError, RequestException, TooManyRedirects # lint-amnesty, pylint: disable=redefined-builtin from openedx.core.djangoapps.ccxcon import api diff --git a/openedx/core/djangoapps/ccxcon/tests/test_api.py b/openedx/core/djangoapps/ccxcon/tests/test_api.py index 08f2b0062e9..659ecfff592 100644 --- a/openedx/core/djangoapps/ccxcon/tests/test_api.py +++ b/openedx/core/djangoapps/ccxcon/tests/test_api.py @@ -7,7 +7,7 @@ import datetime import mock import pytz -import six.moves.urllib.parse # pylint: disable=import-error +import six.moves.urllib.parse # lint-amnesty, pylint: disable=import-error, wrong-import-order from opaque_keys.edx.keys import CourseKey from six.moves import range @@ -83,7 +83,7 @@ class APIsTestCase(SharedModuleStoreTestCase): """ Set up tests """ - super(APIsTestCase, self).setUp() + super(APIsTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Create instructor account self.instructor = AdminFactory.create() # create an instance of modulestore diff --git a/openedx/core/djangoapps/certificates/api.py b/openedx/core/djangoapps/certificates/api.py index cbaefaf8756..ee01cb2cedc 100644 --- a/openedx/core/djangoapps/certificates/api.py +++ b/openedx/core/djangoapps/certificates/api.py @@ -6,7 +6,7 @@ The public API for certificates. import logging from datetime import datetime -import six +import six # lint-amnesty, pylint: disable=unused-import from pytz import UTC from lms.djangoapps.certificates.models import CertificateStatuses, CertificateWhitelist @@ -59,7 +59,7 @@ def is_certificate_valid(certificate): return CourseEnrollment.is_enrolled_as_verified(certificate.user, certificate.course_id) and certificate.is_valid() -def can_show_certificate_message(course, student, course_grade, certificates_enabled_for_course): +def can_show_certificate_message(course, student, course_grade, certificates_enabled_for_course): # lint-amnesty, pylint: disable=missing-function-docstring is_whitelisted = CertificateWhitelist.objects.filter(user=student, course_id=course.id, whitelist=True).exists() auto_cert_gen_enabled = auto_certificate_generation_enabled() has_active_enrollment = CourseEnrollment.is_enrolled(student, course.id) -- GitLab