From ee7f33fb215e40a8d158bd85006d8abfc27fe6ca Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Mon, 27 Dec 2021 12:48:07 -0400 Subject: [PATCH] fix: fix pylint violations introduced by eduNEXT changes Fix pylint violation in lms, cms, openedx and common applications. --- cms/djangoapps/contentstore/views/organization.py | 1 - common/djangoapps/student/models.py | 6 +++--- common/djangoapps/student/tests/test_events.py | 9 ++++----- common/djangoapps/student/tests/test_filters.py | 11 +++++------ lms/djangoapps/certificates/models.py | 4 ++-- lms/djangoapps/course_goals/tests/test_api.py | 1 - openedx/core/djangoapps/course_groups/models.py | 6 +++--- .../djangoapps/course_groups/tests/test_events.py | 5 +---- .../oauth_dispatch/dot_overrides/validators.py | 2 +- openedx/core/djangoapps/user_authn/views/register.py | 2 +- .../djangoapps/user_authn/views/tests/test_login.py | 2 +- 11 files changed, 21 insertions(+), 28 deletions(-) diff --git a/cms/djangoapps/contentstore/views/organization.py b/cms/djangoapps/contentstore/views/organization.py index f29e3efa02b..59daea254e3 100644 --- a/cms/djangoapps/contentstore/views/organization.py +++ b/cms/djangoapps/contentstore/views/organization.py @@ -5,7 +5,6 @@ from django.http import HttpResponse from django.utils.decorators import method_decorator from django.views.generic import View -from organizations.api import get_organizations from openedx.core.djangolib.js_utils import dump_js_escaped_json diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 88be03eb54a..0510e639bf1 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -1451,7 +1451,7 @@ def update_enrollment(self, mode=None, is_active=None, skip_refund=False): pii=UserPersonalData( username=self.user.username, email=self.user.email, - name=self.user.profile.name, + name=self.user.profile.name, # pylint: disable=no-member ), id=self.user.id, is_active=self.user.is_active, @@ -1477,7 +1477,7 @@ def update_enrollment(self, mode=None, is_active=None, skip_refund=False): pii=UserPersonalData( username=self.user.username, email=self.user.email, - name=self.user.profile.name, + name=self.user.profile.name, # pylint: disable=no-member ), id=self.user.id, is_active=self.user.is_active, @@ -1683,7 +1683,7 @@ def enroll(cls, user, course_key, mode=None, check_access=False, can_upgrade=Fal pii=UserPersonalData( username=user.username, email=user.email, - name=user.profile.name, + name=user.profile.name, # pylint: disable=no-member ), id=user.id, is_active=user.is_active, diff --git a/common/djangoapps/student/tests/test_events.py b/common/djangoapps/student/tests/test_events.py index 4e83838342d..0cceefb2f94 100644 --- a/common/djangoapps/student/tests/test_events.py +++ b/common/djangoapps/student/tests/test_events.py @@ -10,10 +10,6 @@ from django.test import TestCase from django_countries.fields import Country -from common.djangoapps.student.models import CourseEnrollmentAllowed, CourseEnrollment -from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory, UserProfileFactory -from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin - from openedx_events.learning.data import ( CourseData, CourseEnrollmentData, @@ -26,8 +22,11 @@ COURSE_UNENROLLMENT_COMPLETED, ) from openedx_events.tests.utils import OpenEdxEventsTestMixin -from openedx.core.djangolib.testing.utils import skip_unless_lms +from common.djangoapps.student.models import CourseEnrollmentAllowed, CourseEnrollment +from common.djangoapps.student.tests.factories import CourseEnrollmentAllowedFactory, UserFactory, UserProfileFactory +from common.djangoapps.student.tests.tests import UserSettingsEventTestMixin +from openedx.core.djangolib.testing.utils import skip_unless_lms from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/common/djangoapps/student/tests/test_filters.py b/common/djangoapps/student/tests/test_filters.py index d36fbb88271..edb2865a57a 100644 --- a/common/djangoapps/student/tests/test_filters.py +++ b/common/djangoapps/student/tests/test_filters.py @@ -1,26 +1,25 @@ """ Test that various filters are fired for models in the student app. """ +from django.test import override_settings +from openedx_filters.learning.enrollment import PreEnrollmentFilter +from openedx_filters import PipelineStep + from common.djangoapps.student.models import CourseEnrollment, EnrollmentNotAllowed from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from django.test import TestCase, override_settings -from openedx_filters.learning.enrollment import PreEnrollmentFilter - from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from openedx_filters import PipelineStep - class TestEnrollmentPipelineStep(PipelineStep): """ Utility function used when getting steps for pipeline. """ - def run(self, user, course_key, mode): + def run(self, user, course_key, mode): # pylint: disable=unused-argument, arguments-differ """Pipeline steps that changes mode to honor.""" if mode == "no-id-professional": raise PreEnrollmentFilter.PreventEnrollment() diff --git a/lms/djangoapps/certificates/models.py b/lms/djangoapps/certificates/models.py index 4be726ef290..3f5fc4d975f 100644 --- a/lms/djangoapps/certificates/models.py +++ b/lms/djangoapps/certificates/models.py @@ -23,6 +23,8 @@ from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField from simple_history.models import HistoricalRecords +from openedx_events.learning.data import CourseData, UserData, UserPersonalData, CertificateData +from openedx_events.learning.signals import CERTIFICATE_CHANGED, CERTIFICATE_CREATED, CERTIFICATE_REVOKED from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.util.milestones_helpers import fulfill_course_milestone, is_prerequisite_courses_enabled @@ -33,8 +35,6 @@ from openedx.core.djangoapps.signals.signals import COURSE_CERT_AWARDED, COURSE_CERT_CHANGED, COURSE_CERT_REVOKED from openedx.core.djangoapps.xmodule_django.models import NoneToEmptyManager -from openedx_events.learning.data import CourseData, UserData, UserPersonalData, CertificateData -from openedx_events.learning.signals import CERTIFICATE_CHANGED, CERTIFICATE_CREATED, CERTIFICATE_REVOKED log = logging.getLogger(__name__) User = get_user_model() diff --git a/lms/djangoapps/course_goals/tests/test_api.py b/lms/djangoapps/course_goals/tests/test_api.py index 033bca2c9a6..1e099ef91ad 100644 --- a/lms/djangoapps/course_goals/tests/test_api.py +++ b/lms/djangoapps/course_goals/tests/test_api.py @@ -5,7 +5,6 @@ from unittest import mock -from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.test.utils import override_settings from django.urls import reverse from rest_framework.test import APIClient diff --git a/openedx/core/djangoapps/course_groups/models.py b/openedx/core/djangoapps/course_groups/models.py index d3ef13c776d..602fa5af7eb 100644 --- a/openedx/core/djangoapps/course_groups/models.py +++ b/openedx/core/djangoapps/course_groups/models.py @@ -13,11 +13,11 @@ from django.dispatch import receiver from django.utils.encoding import python_2_unicode_compatible from opaque_keys.edx.django.models import CourseKeyField +from openedx_events.learning.data import CohortData, CourseData, UserData, UserPersonalData +from openedx_events.learning.signals import COHORT_MEMBERSHIP_CHANGED from openedx.core.djangolib.model_mixins import DeletableByUserValue -from openedx_events.learning.data import CohortData, CourseData, UserData, UserPersonalData -from openedx_events.learning.signals import COHORT_MEMBERSHIP_CHANGED log = logging.getLogger(__name__) @@ -139,7 +139,7 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields pii=UserPersonalData( username=self.user.username, email=self.user.email, - name=self.user.profile.name, + name=self.user.profile.name, # pylint: disable=no-member ), id=self.user.id, is_active=self.user.is_active, diff --git a/openedx/core/djangoapps/course_groups/tests/test_events.py b/openedx/core/djangoapps/course_groups/tests/test_events.py index 2a1cc040470..d4b887155e9 100644 --- a/openedx/core/djangoapps/course_groups/tests/test_events.py +++ b/openedx/core/djangoapps/course_groups/tests/test_events.py @@ -4,19 +4,16 @@ Classes: CohortEventTest: Test event sent after cohort membership changes. """ -from openedx.core.djangoapps.course_groups.models import CohortMembership from unittest.mock import Mock - from openedx_events.learning.data import CohortData, CourseData, UserData, UserPersonalData from openedx_events.learning.signals import COHORT_MEMBERSHIP_CHANGED from openedx_events.tests.utils import OpenEdxEventsTestMixin +from openedx.core.djangoapps.course_groups.models import CohortMembership from common.djangoapps.student.tests.factories import UserFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory from openedx.core.djangolib.testing.utils import skip_unless_lms - from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory - from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py index 673fb5cdb67..764db109e2d 100644 --- a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py +++ b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py @@ -87,7 +87,7 @@ def save_bearer_token(self, token, request, *args, **kwargs): # Without this modification the BearerToken class will set this to 3600 request.expires_in = getattr(settings, 'CLIENT_CREDENTIALS_ACCESS_TOKEN_EXPIRE_SECONDS', 31557600) - super(EdxOAuth2Validator, self).save_bearer_token(token, request, *args, **kwargs) + super().save_bearer_token(token, request, *args, **kwargs) is_restricted_client = self._update_token_expiry_if_restricted_client(token, request.client) if not is_restricted_client: diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 2670d512f10..9edeb227e40 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -253,7 +253,7 @@ def create_account_with_params(request, params): pii=UserPersonalData( username=user.username, email=user.email, - name=user.profile.name, + name=user.profile.name, # pylint: disable=no-member ), id=user.id, is_active=user.is_active, diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index b0ec6e732a3..3c356cd5fa5 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -20,8 +20,8 @@ from django.urls import NoReverseMatch, reverse from edx_toggles.toggles.testutils import override_waffle_flag, override_waffle_switch from freezegun import freeze_time -from common.djangoapps.student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory from openedx_events.tests.utils import OpenEdxEventsTestMixin +from common.djangoapps.student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory from openedx.core.djangoapps.password_policy.compliance import ( NonCompliantPasswordException,