From d5a5e25feffc3a4db55bddbcfe04cf857b20b38a Mon Sep 17 00:00:00 2001 From: Bernard Szabo Date: Thu, 24 Nov 2022 16:44:35 -0500 Subject: [PATCH] feat: TNL-10136 fix lint errors And import cross-references And wrap-around lines --- .../student/models/course_enrollment.py | 10 +++++---- common/djangoapps/student/models/user.py | 22 ++++++++++++------- common/djangoapps/student/tests/test_views.py | 3 ++- lms/djangoapps/courseware/tests/test_tabs.py | 3 ++- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/common/djangoapps/student/models/course_enrollment.py b/common/djangoapps/student/models/course_enrollment.py index a8f356f2b2..faa09a6d20 100644 --- a/common/djangoapps/student/models/course_enrollment.py +++ b/common/djangoapps/student/models/course_enrollment.py @@ -11,8 +11,8 @@ from django.conf import settings from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from django.core.cache import cache from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist -from django.core.validators import FileExtensionValidator, RegexValidator -from django.db import IntegrityError, models +from django.core.validators import FileExtensionValidator +from django.db import models from django.db.models import Count, Index, Q from django.dispatch import receiver from django.utils.functional import cached_property @@ -20,7 +20,7 @@ from django.utils.translation import gettext_lazy as _ from edx_django_utils.cache import RequestCache, TieredCache, get_cache_key from eventtracking import tracker from model_utils.models import TimeStampedModel -from opaque_keys.edx.django.models import CourseKeyField, LearningContextKeyField +from opaque_keys.edx.django.models import CourseKeyField from opaque_keys.edx.keys import CourseKey from openedx_events.learning.data import CourseData, CourseEnrollmentData, UserData, UserPersonalData from openedx_events.learning.signals import ( @@ -29,7 +29,7 @@ from openedx_events.learning.signals import ( COURSE_UNENROLLMENT_COMPLETED, ) from openedx_filters.learning.filters import CourseEnrollmentStarted, CourseUnenrollmentStarted -from pytz import UTC, timezone +from pytz import UTC from requests.exceptions import HTTPError, RequestException from simple_history.models import HistoricalRecords @@ -61,6 +61,7 @@ log = logging.getLogger(__name__) AUDIT_LOG = logging.getLogger("audit") + # ENROLL signal used for free enrollment only class EnrollStatusChange: """ @@ -607,6 +608,7 @@ class CourseEnrollment(models.Model): segment_properties['course_start'] = self.course.start segment_properties['course_pacing'] = self.course.pacing + from .user import is_personalized_recommendation_for_user course_key = f'{self.course_id.org}+{self.course_id.course}' is_personalized_recommendation = is_personalized_recommendation_for_user(course_key) if is_personalized_recommendation is not None: diff --git a/common/djangoapps/student/models/user.py b/common/djangoapps/student/models/user.py index 9dd6024bf0..92fc8c6e7d 100644 --- a/common/djangoapps/student/models/user.py +++ b/common/djangoapps/student/models/user.py @@ -15,12 +15,20 @@ import hashlib # lint-amnesty, pylint: disable=wrong-import-order import json # lint-amnesty, pylint: disable=wrong-import-order import logging # lint-amnesty, pylint: disable=wrong-import-order import uuid # lint-amnesty, pylint: disable=wrong-import-order -from datetime import date, datetime, timedelta # lint-amnesty, pylint: disable=wrong-import-order +from datetime import datetime, timedelta # lint-amnesty, pylint: disable=wrong-import-order from functools import total_ordering # lint-amnesty, pylint: disable=wrong-import-order from importlib import import_module # lint-amnesty, pylint: disable=wrong-import-order -from urllib.parse import unquote, urlencode, urljoin +from urllib.parse import unquote, urlencode import crum + +from .course_enrollment import ( + ALLOWEDTOENROLL_TO_ENROLLED, + CourseEnrollment, + CourseEnrollmentAllowed, + ManualEnrollmentAudit +) + from config_models.models import ConfigurationModel from django.apps import apps from django.conf import settings @@ -28,10 +36,10 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imp from django.contrib.auth.signals import user_logged_in, user_logged_out from django.contrib.sites.models import Site from django.core.cache import cache -from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist from django.core.validators import FileExtensionValidator, RegexValidator from django.db import IntegrityError, models -from django.db.models import Count, Index, Q +from django.db.models import Q from django.db.models.signals import post_save, pre_save from django.db.utils import ProgrammingError from django.dispatch import receiver @@ -39,14 +47,14 @@ from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_noop from django_countries.fields import CountryField from edx_django_utils import monitoring -from edx_django_utils.cache import RequestCache, TieredCache, get_cache_key +from edx_django_utils.cache import RequestCache from model_utils.models import TimeStampedModel from opaque_keys.edx.django.models import CourseKeyField, LearningContextKeyField from pytz import UTC, timezone from user_util import user_util import openedx.core.djangoapps.django_comment_common.comment_client as cc -from common.djangoapps.track import contexts, segment +from common.djangoapps.track import segment from common.djangoapps.util.model_utils import emit_field_changed_events, get_changed_fields_dict from lms.djangoapps.courseware.toggles import streak_celebration_is_active from openedx.core.djangoapps.signals.signals import USER_ACCOUNT_ACTIVATED @@ -1045,8 +1053,6 @@ class LoginFailures(models.Model): verbose_name_plural = 'Login Failures' - - @total_ordering class CourseAccessRole(models.Model): """ diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 73648ea62c..4e2a481813 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -156,7 +156,8 @@ class TestStudentDashboardUnenrollments(SharedModuleStoreTestCase): assert json.loads(response.content.decode('utf-8')) == {'course_refundable_status': True} assert response.status_code == 200 - with patch('common.djangoapps.student.models.course_enrollment.CourseEnrollment.refundable', return_value=False): + REFUNDABLE_METHOD_NAME = 'common.djangoapps.student.models.course_enrollment.CourseEnrollment.refundable' + with patch(REFUNDABLE_METHOD_NAME, return_value=False): response = self.client.get(reverse('course_run_refund_status', kwargs={'course_id': self.course.id})) assert json.loads(response.content.decode('utf-8')) == {'course_refundable_status': False} diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index 6714cecb67..c2f65e069a 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -761,7 +761,8 @@ class DiscussionLinkTestCase(TabTestCase): is_enrolled=True ): """Helper function to verify whether the discussion tab exists and can be displayed""" - with patch('common.djangoapps.student.models.course_enrollment.CourseEnrollment.is_enrolled') as check_is_enrolled: + IS_ENROLLED_METHOD_NAME = 'common.djangoapps.student.models.course_enrollment.CourseEnrollment.is_enrolled' + with patch(IS_ENROLLED_METHOD_NAME) as check_is_enrolled: self.course.tabs = tab_list self.course.discussion_link = discussion_link_in_course discussion_tab = xmodule_tabs.CourseTabList.get_discussion(self.course)