BOM-2323 : Pylint amnesty in embargo and enrollments apps (#26368)

* pylint amnesty in openedx apps
This commit is contained in:
M. Zulqarnain
2021-02-04 15:32:59 +05:00
committed by GitHub
parent 99c169c444
commit 39b207007c
29 changed files with 94 additions and 93 deletions

View File

@@ -8,4 +8,4 @@ class InvalidAccessPoint(Exception):
msg = (
u"Access point '{access_point}' should be either 'enrollment' or 'courseware'"
).format(access_point=access_point)
super(InvalidAccessPoint, self).__init__(msg, *args, **kwargs)
super(InvalidAccessPoint, self).__init__(msg, *args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments

View File

@@ -48,7 +48,7 @@ class RestrictedCourseForm(forms.ModelForm):
try:
course_key = CourseKey.from_string(cleaned_id)
except InvalidKeyError:
raise forms.ValidationError(error_msg)
raise forms.ValidationError(error_msg) # lint-amnesty, pylint: disable=raise-missing-from
if not modulestore().has_course(course_key):
raise forms.ValidationError(error_msg)

View File

@@ -62,7 +62,7 @@ class EmbargoMiddleware(MiddlewareMixin):
# If embargoing is turned off, make this middleware do nothing
if not settings.FEATURES.get('EMBARGO'):
raise MiddlewareNotUsed()
super(EmbargoMiddleware, self).__init__(*args, **kwargs)
super(EmbargoMiddleware, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
def process_request(self, request):
"""Block requests based on embargo rules.

View File

@@ -14,16 +14,16 @@ class CountryFactory(DjangoModelFactory):
country = 'US'
class RestrictedCourseFactory(DjangoModelFactory):
class RestrictedCourseFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = RestrictedCourse
@factory.lazy_attribute
def course_key(self):
return CourseFactory().id
return CourseFactory().id # lint-amnesty, pylint: disable=no-member
class CountryAccessRuleFactory(DjangoModelFactory):
class CountryAccessRuleFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = CountryAccessRule

View File

@@ -49,7 +49,7 @@ class EmbargoCheckAccessApiTests(ModuleStoreTestCase):
ENABLED_CACHES = ['default', 'mongo_metadata_inheritance', 'loc_cache']
def setUp(self):
super(EmbargoCheckAccessApiTests, self).setUp()
super(EmbargoCheckAccessApiTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory.create()
self.user = UserFactory.create()
self.restricted_course = RestrictedCourse.objects.create(course_key=self.course.id)
@@ -270,7 +270,7 @@ class EmbargoMessageUrlApiTests(UrlResetMixin, ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(EmbargoMessageUrlApiTests, self).setUp()
super(EmbargoMessageUrlApiTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory.create()
@ddt.data(

View File

@@ -59,7 +59,7 @@ class IPFilterFormTest(TestCase):
"""Test form for adding [black|white]list IP addresses"""
def tearDown(self):
super(IPFilterFormTest, self).tearDown()
super(IPFilterFormTest, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments
# Explicitly clear ConfigurationModel's cache so tests have a clear cache
# and don't interfere with each other
cache.clear()

View File

@@ -38,7 +38,7 @@ class EmbargoMiddlewareAccessTests(UrlResetMixin, ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(EmbargoMiddlewareAccessTests, self).setUp()
super(EmbargoMiddlewareAccessTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.user = UserFactory(username=self.USERNAME, password=self.PASSWORD)
self.course = CourseFactory.create()
self.client.login(username=self.USERNAME, password=self.PASSWORD)

View File

@@ -261,7 +261,7 @@ class CourseAccessRuleHistoryTest(TestCase):
"""Test course access rule history. """
def setUp(self):
super(CourseAccessRuleHistoryTest, self).setUp()
super(CourseAccessRuleHistoryTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course_key = CourseLocator('edx', 'DemoX', 'Demo_Course')
self.restricted_course = RestrictedCourse.objects.create(course_key=self.course_key)
self.countries = {

View File

@@ -11,13 +11,13 @@ from mock import patch, MagicMock
from .factories import CountryAccessRuleFactory, RestrictedCourseFactory
from .. import messages
from lms.djangoapps.course_api.tests.mixins import CourseApiFactoryMixin
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.util.testing import UrlResetMixin
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from lms.djangoapps.course_api.tests.mixins import CourseApiFactoryMixin # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme # lint-amnesty, pylint: disable=wrong-import-order
from common.djangoapps.student.tests.factories import UserFactory # lint-amnesty, pylint: disable=wrong-import-order
from common.djangoapps.util.testing import UrlResetMixin # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
@skip_unless_lms
@@ -46,7 +46,7 @@ class CourseAccessMessageViewTest(CacheIsolationTestCase, UrlResetMixin):
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(CourseAccessMessageViewTest, self).setUp()
super(CourseAccessMessageViewTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
@ddt.data(*list(messages.ENROLL_MESSAGES.keys()))
def test_enrollment_messages(self, msg_key):
@@ -102,11 +102,11 @@ class CheckCourseAccessViewTest(CourseApiFactoryMixin, ModuleStoreTestCase):
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
super(CheckCourseAccessViewTest, self).setUp()
super(CheckCourseAccessViewTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.url = reverse('api_embargo:v1_course_access')
user = UserFactory(is_staff=True)
self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD)
self.course_id = str(CourseFactory().id)
self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD) # lint-amnesty, pylint: disable=protected-access
self.course_id = str(CourseFactory().id) # lint-amnesty, pylint: disable=no-member
self.request_data = {
'course_ids': [self.course_id],
'ip_address': '0.0.0.0',
@@ -159,7 +159,7 @@ class CheckCourseAccessViewTest(CourseApiFactoryMixin, ModuleStoreTestCase):
def test_course_access_endpoint_with_non_staff_user(self):
user = UserFactory(is_staff=False)
self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD)
self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD) # lint-amnesty, pylint: disable=protected-access
response = self.client.get(self.url, data=self.request_data)
self.assertEqual(response.status_code, 403)

View File

@@ -1,7 +1,7 @@
"""Views served by the embargo app. """
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.http import Http404
from django.views.generic.base import View
from opaque_keys import InvalidKeyError
@@ -17,7 +17,7 @@ from . import messages
from .api import check_course_access
class CheckCourseAccessView(APIView):
class CheckCourseAccessView(APIView): # lint-amnesty, pylint: disable=missing-class-docstring
permission_classes = (permissions.IsAuthenticated, permissions.IsAdminUser)
def get(self, request):
@@ -49,7 +49,7 @@ class CheckCourseAccessView(APIView):
response['access'] = False
break
except InvalidKeyError:
raise ValidationError('Invalid course_ids')
raise ValidationError('Invalid course_ids') # lint-amnesty, pylint: disable=raise-missing-from
else:
raise ValidationError('Missing parameters')

View File

@@ -1,3 +1,3 @@
"""
""" # lint-amnesty, pylint: disable=django-not-configured
Enrollment API helpers and settings
"""

View File

@@ -265,7 +265,7 @@ def update_enrollment(
if mode is not None:
validate_course_mode(course_id, mode, is_active=is_active, include_expired=include_expired)
enrollment = _data_api().update_course_enrollment(username, course_id, mode=mode, is_active=is_active)
if enrollment is None:
if enrollment is None: # lint-amnesty, pylint: disable=no-else-raise
msg = u"Course Enrollment not found for user {user} in course {course}".format(user=username, course=course_id)
log.warning(msg)
raise errors.EnrollmentNotFoundError(msg)
@@ -342,7 +342,7 @@ def get_course_enrollment_details(course_id, include_expired=False):
except Exception:
# Catch any unexpected errors during caching.
log.exception(u"Error occurred while caching course enrollment details for course %s", course_id)
raise errors.CourseEnrollmentError(u"An unexpected error occurred while retrieving course enrollment details.")
raise errors.CourseEnrollmentError(u"An unexpected error occurred while retrieving course enrollment details.") # lint-amnesty, pylint: disable=raise-missing-from
return course_enrollment_details
@@ -544,4 +544,4 @@ def _data_api():
return importlib.import_module(api_path)
except (ImportError, ValueError):
log.exception(u"Could not load module at '{path}'".format(path=api_path))
raise errors.EnrollmentApiLoadError(api_path)
raise errors.EnrollmentApiLoadError(api_path) # lint-amnesty, pylint: disable=raise-missing-from

View File

@@ -6,7 +6,7 @@ source to be used throughout the API.
import logging
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.db import transaction
from opaque_keys.edx.keys import CourseKey
from six import text_type
@@ -144,20 +144,20 @@ def create_course_enrollment(username, course_id, mode, is_active):
except User.DoesNotExist:
msg = u"Not user with username '{username}' found.".format(username=username)
log.warning(msg)
raise UserNotFoundError(msg)
raise UserNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
try:
enrollment = CourseEnrollment.enroll(user, course_key, check_access=True)
return _update_enrollment(enrollment, is_active=is_active, mode=mode)
except NonExistentCourseError as err:
raise CourseNotFoundError(text_type(err))
raise CourseNotFoundError(text_type(err)) # lint-amnesty, pylint: disable=raise-missing-from
except EnrollmentClosedError as err:
raise CourseEnrollmentClosedError(text_type(err))
raise CourseEnrollmentClosedError(text_type(err)) # lint-amnesty, pylint: disable=raise-missing-from
except CourseFullError as err:
raise CourseEnrollmentFullError(text_type(err))
raise CourseEnrollmentFullError(text_type(err)) # lint-amnesty, pylint: disable=raise-missing-from
except AlreadyEnrolledError as err:
enrollment = get_course_enrollment(username, course_id)
raise CourseEnrollmentExistsError(text_type(err), enrollment)
raise CourseEnrollmentExistsError(text_type(err), enrollment) # lint-amnesty, pylint: disable=raise-missing-from
def update_course_enrollment(username, course_id, mode=None, is_active=None):
@@ -182,7 +182,7 @@ def update_course_enrollment(username, course_id, mode=None, is_active=None):
except User.DoesNotExist:
msg = u"Not user with username '{username}' found.".format(username=username)
log.warning(msg)
raise UserNotFoundError(msg)
raise UserNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
try:
enrollment = CourseEnrollment.objects.get(user=user, course_id=course_key)
@@ -257,7 +257,7 @@ def unenroll_user_from_all_courses(username):
for enrollment in enrollments:
_update_enrollment(enrollment, is_active=False)
return set([str(enrollment.course_id.org) for enrollment in enrollments])
return set([str(enrollment.course_id.org) for enrollment in enrollments]) # lint-amnesty, pylint: disable=consider-using-set-comprehension
def _get_user(username):
@@ -273,7 +273,7 @@ def _get_user(username):
except User.DoesNotExist:
msg = u"Not user with username '{username}' found.".format(username=username)
log.warning(msg)
raise UserNotFoundError(msg)
raise UserNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
def _update_enrollment(enrollment, is_active=None, mode=None):
@@ -337,7 +337,7 @@ def get_course_enrollment_info(course_id, include_expired=False):
except CourseOverview.DoesNotExist:
msg = u"Requested enrollment information for unknown course {course}".format(course=course_id)
log.warning(msg)
raise CourseNotFoundError(msg)
raise CourseNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
else:
return CourseSerializer(course, include_expired=include_expired).data

View File

@@ -8,7 +8,7 @@ class CourseEnrollmentError(Exception):
"""
def __init__(self, msg, data=None):
super(CourseEnrollmentError, self).__init__(msg)
super(CourseEnrollmentError, self).__init__(msg) # lint-amnesty, pylint: disable=super-with-arguments
# Corresponding information to help resolve the error.
self.data = data
@@ -25,29 +25,29 @@ class CourseEnrollmentFullError(CourseEnrollmentError):
pass
class CourseEnrollmentExistsError(CourseEnrollmentError):
class CourseEnrollmentExistsError(CourseEnrollmentError): # lint-amnesty, pylint: disable=missing-class-docstring
enrollment = None
def __init__(self, message, enrollment):
super(CourseEnrollmentExistsError, self).__init__(message)
super(CourseEnrollmentExistsError, self).__init__(message) # lint-amnesty, pylint: disable=super-with-arguments
self.enrollment = enrollment
class CourseModeNotFoundError(CourseEnrollmentError):
"""The requested course mode could not be found."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class EnrollmentNotFoundError(CourseEnrollmentError):
"""The requested enrollment could not be found."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class EnrollmentApiLoadError(CourseEnrollmentError):
"""The data API could not be loaded."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class InvalidEnrollmentAttribute(CourseEnrollmentError):
"""Enrollment Attributes could not be validated"""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass

View File

@@ -28,7 +28,7 @@ class CourseEnrollmentsApiListForm(Form):
try:
return CourseKey.from_string(course_id)
except InvalidKeyError:
raise ValidationError(u"'{}' is not a valid course id.".format(course_id))
raise ValidationError(u"'{}' is not a valid course id.".format(course_id)) # lint-amnesty, pylint: disable=raise-missing-from
return course_id
def clean_username(self):

View File

@@ -2,7 +2,7 @@
Management command for enrolling a user into a course via the enrollment api
"""
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.core.management.base import BaseCommand
from openedx.core.djangoapps.enrollments.data import CourseEnrollmentExistsError
from openedx.core.djangoapps.enrollments.api import add_enrollment

View File

@@ -14,8 +14,8 @@ from common.djangoapps.student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
import six
from six.moves import range
import six # lint-amnesty, pylint: disable=wrong-import-order
from six.moves import range # lint-amnesty, pylint: disable=wrong-import-order
@ddt.ddt
@@ -31,7 +31,7 @@ class EnrollManagementCommandTest(SharedModuleStoreTestCase):
cls.course = CourseFactory.create(org='fooX', number='007')
def setUp(self):
super(EnrollManagementCommandTest, self).setUp()
super(EnrollManagementCommandTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course_id = six.text_type(self.course.id)
self.username = 'ralph' + uuid4().hex
self.user_email = self.username + '@example.com'

View File

@@ -51,7 +51,7 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
def __init__(self, *args, **kwargs):
self.include_expired = kwargs.pop("include_expired", False)
super(CourseSerializer, self).__init__(*args, **kwargs)
super(CourseSerializer, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
def get_course_modes(self, obj):
"""
@@ -96,7 +96,7 @@ class CourseEnrollmentsApiListSerializer(CourseEnrollmentSerializer):
course_id = serializers.CharField(source='course_overview.id')
def __init__(self, *args, **kwargs):
super(CourseEnrollmentsApiListSerializer, self).__init__(*args, **kwargs)
super(CourseEnrollmentsApiListSerializer, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
self.fields.pop('course_details')
class Meta(CourseEnrollmentSerializer.Meta):

View File

@@ -33,7 +33,7 @@ class EnrollmentTest(CacheIsolationTestCase):
ENABLED_CACHES = ['default']
def setUp(self):
super(EnrollmentTest, self).setUp()
super(EnrollmentTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
fake_data_api.reset()
@ddt.data(

View File

@@ -26,7 +26,7 @@ from openedx.core.djangoapps.enrollments.errors import (
)
from openedx.core.djangoapps.enrollments.serializers import CourseEnrollmentSerializer
from openedx.core.lib.exceptions import CourseNotFoundError
from common.djangoapps.student.models import AlreadyEnrolledError, CourseEnrollment, CourseFullError, EnrollmentClosedError
from common.djangoapps.student.models import AlreadyEnrolledError, CourseEnrollment, CourseFullError, EnrollmentClosedError # lint-amnesty, pylint: disable=line-too-long
from common.djangoapps.student.tests.factories import CourseAccessRoleFactory, UserFactory, CourseEnrollmentFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
@@ -45,7 +45,7 @@ class EnrollmentDataTest(ModuleStoreTestCase):
def setUp(self):
"""Create a course and user, then log in. """
super(EnrollmentDataTest, self).setUp()
super(EnrollmentDataTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
self.client.login(username=self.USERNAME, password=self.PASSWORD)

View File

@@ -171,7 +171,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentTest, self).setUp()
super(EnrollmentTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.rate_limit_config = RateLimitConfiguration.current()
self.rate_limit_config.enabled = False
@@ -1093,7 +1093,7 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente
linked_enterprise_customer='this-is-a-real-uuid',
)
self.assertEqual(
httpretty.last_request().path,
httpretty.last_request().path, # lint-amnesty, pylint: disable=no-member
'/consent/api/v1/data_sharing_consent',
)
self.assertEqual(
@@ -1164,7 +1164,7 @@ class EnrollmentEmbargoTest(EnrollmentTestMixin, UrlResetMixin, ModuleStoreTestC
@patch.dict(settings.FEATURES, {'EMBARGO': True})
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentEmbargoTest, self).setUp()
super(EnrollmentEmbargoTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory.create()
# Load a CourseOverview. This initial load should result in a cache
@@ -1294,7 +1294,7 @@ class EnrollmentCrossDomainTest(ModuleStoreTestCase):
def setUp(self):
""" Create a course and user, then log in. """
super(EnrollmentCrossDomainTest, self).setUp()
super(EnrollmentCrossDomainTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course = CourseFactory.create()
self.user = UserFactory.create(username=self.USERNAME, email=self.EMAIL, password=self.PASSWORD)
@@ -1357,7 +1357,7 @@ class UnenrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase):
def setUp(self):
""" Create a course and user, then log in. """
super(UnenrollmentTest, self).setUp()
super(UnenrollmentTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.superuser = SuperuserFactory()
# Pass emit_signals when creating the course so it would be cached
# as a CourseOverview. Enrollments require a cached CourseOverview.
@@ -1501,7 +1501,7 @@ class UserRoleTest(ModuleStoreTestCase):
def setUp(self):
""" Create a course and user, then log in. """
super(UserRoleTest, self).setUp()
super(UserRoleTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.course1 = CourseFactory.create(emit_signals=True, org="org1", course="course1", run="run1")
self.course2 = CourseFactory.create(emit_signals=True, org="org2", course="course2", run="run2")
self.user = UserFactory.create(
@@ -1602,7 +1602,7 @@ class CourseEnrollmentsApiListTest(APITestCase, ModuleStoreTestCase):
CREATED_DATA = datetime.datetime(2018, 1, 1, 0, 0, 1, tzinfo=pytz.UTC)
def setUp(self):
super(CourseEnrollmentsApiListTest, self).setUp()
super(CourseEnrollmentsApiListTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.rate_limit_config = RateLimitConfiguration.current()
self.rate_limit_config.enabled = False
self.rate_limit_config.save()

View File

@@ -10,12 +10,12 @@ import logging
from six import text_type
from common.djangoapps.course_modes.models import CourseMode
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.utils.decorators import method_decorator
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from django.core.exceptions import ObjectDoesNotExist, ValidationError # lint-amnesty, pylint: disable=wrong-import-order
from django.utils.decorators import method_decorator # lint-amnesty, pylint: disable=wrong-import-order
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication # lint-amnesty, pylint: disable=wrong-import-order
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser # lint-amnesty, pylint: disable=wrong-import-order
from opaque_keys import InvalidKeyError # lint-amnesty, pylint: disable=wrong-import-order
from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.djangoapps.cors_csrf.authentication import SessionAuthenticationCrossDomainCsrf
from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain
from openedx.core.djangoapps.course_groups.cohorts import CourseUserGroup, add_user_to_cohort, get_cohort_by_name
@@ -41,11 +41,11 @@ from openedx.features.enterprise_support.api import (
EnterpriseApiServiceClient,
enterprise_enabled
)
from rest_framework import permissions, status
from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView
from rest_framework import permissions, status # lint-amnesty, pylint: disable=wrong-import-order
from rest_framework.generics import ListAPIView # lint-amnesty, pylint: disable=wrong-import-order
from rest_framework.response import Response # lint-amnesty, pylint: disable=wrong-import-order
from rest_framework.throttling import UserRateThrottle # lint-amnesty, pylint: disable=wrong-import-order
from rest_framework.views import APIView # lint-amnesty, pylint: disable=wrong-import-order
from common.djangoapps.student.auth import user_has_role
from common.djangoapps.student.models import CourseEnrollment, User
from common.djangoapps.student.roles import CourseStaffRole, GlobalStaff
@@ -59,7 +59,7 @@ REQUIRED_ATTRIBUTES = {
class EnrollmentCrossDomainSessionAuth(SessionAuthenticationAllowInactiveUser, SessionAuthenticationCrossDomainCsrf):
"""Session authentication that allows inactive users and cross-domain requests. """
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class ApiKeyPermissionMixIn(object):
@@ -99,7 +99,7 @@ class EnrollmentUserThrottle(UserRateThrottle, ApiKeyPermissionMixIn):
self.rate = self.get_rate()
self.num_requests, self.duration = self.parse_rate(self.rate)
return self.has_api_key_permissions(request) or super(EnrollmentUserThrottle, self).allow_request(request, view)
return self.has_api_key_permissions(request) or super(EnrollmentUserThrottle, self).allow_request(request, view) # lint-amnesty, pylint: disable=super-with-arguments
@can_disable_rate_limit
@@ -749,7 +749,7 @@ class EnrollmentListView(APIView, ApiKeyPermissionMixIn):
except EnterpriseApiException as error:
log.exception(u"An unexpected error occurred while creating the new EnterpriseCourseEnrollment "
u"for user [%s] in course run [%s]", username, course_id)
raise CourseEnrollmentError(text_type(error))
raise CourseEnrollmentError(text_type(error)) # lint-amnesty, pylint: disable=raise-missing-from
kwargs = {
'username': username,
'course_id': text_type(course_id),

View File

@@ -1,4 +1,4 @@
"""
""" # lint-amnesty, pylint: disable=django-not-configured
edX Platform support for external user IDs.
This package will be used to support generating external User IDs to be shared

View File

@@ -1,3 +1,4 @@
# lint-amnesty, pylint: disable=missing-module-docstring
import csv
from logging import getLogger
@@ -25,13 +26,13 @@ class CsvImportForm(forms.Form):
@admin.register(ExternalId)
class ExternalIdAdmin(admin.ModelAdmin):
class ExternalIdAdmin(admin.ModelAdmin): # lint-amnesty, pylint: disable=missing-class-docstring
change_list_template = 'admin/external_user_ids/generate_external_user_ids.html'
list_display = ('user', 'external_user_id', 'external_id_type')
template = 'openedx/core/djangoapps/external_user_ids/templates/admin/generate_external_ids_template.html'
def get_urls(self):
urls = super(ExternalIdAdmin, self).get_urls()
urls = super(ExternalIdAdmin, self).get_urls() # lint-amnesty, pylint: disable=super-with-arguments
custom_urls = [
url(
r'^bulk_generate_external_ids/$',
@@ -49,7 +50,7 @@ class ExternalIdAdmin(admin.ModelAdmin):
'External IDs already exist for: {}\n'.format(existing_id)
)
def process_generate_ids_request(self, user_id_list, id_type, request, redirect_url):
def process_generate_ids_request(self, user_id_list, id_type, request, redirect_url): # lint-amnesty, pylint: disable=missing-function-docstring
created_id_list = []
existing_id = []
@@ -57,7 +58,7 @@ class ExternalIdAdmin(admin.ModelAdmin):
id__in=user_id_list
)
for user in user_list:
new_external_id, created = ExternalId.objects.get_or_create(
new_external_id, created = ExternalId.objects.get_or_create( # lint-amnesty, pylint: disable=unused-variable
user=user,
external_id_type=id_type,
)
@@ -85,7 +86,7 @@ class ExternalIdAdmin(admin.ModelAdmin):
context
)
def generate_ids_form(self, request):
def generate_ids_form(self, request): # lint-amnesty, pylint: disable=missing-function-docstring
if request.method == 'POST':
redirect_url = reverse(
'admin:external_user_ids_externalid_changelist',

View File

@@ -5,7 +5,7 @@ Models for External User Ids that are sent out of Open edX
import uuid as uuid_tools
from logging import getLogger
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.db import models
from model_utils.models import TimeStampedModel
from simple_history.models import HistoricalRecords

View File

@@ -10,7 +10,7 @@ from factory.fuzzy import FuzzyChoice, FuzzyText
from openedx.core.djangoapps.external_user_ids.models import ExternalId, ExternalIdType
class ExternalIDTypeFactory(factory.django.DjangoModelFactory):
class ExternalIDTypeFactory(factory.django.DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = ExternalIdType
@@ -18,7 +18,7 @@ class ExternalIDTypeFactory(factory.django.DjangoModelFactory):
description = FuzzyText()
class ExternalIdFactory(factory.django.DjangoModelFactory):
class ExternalIdFactory(factory.django.DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = ExternalId

View File

@@ -1,6 +1,6 @@
# """
# Test the logic behind the Generate External IDs tools in Admin
# """
"""
Test the logic behind the Generate External IDs tools in Admin
"""
import mock
from django.contrib.admin.sites import AdminSite
from django.test import TestCase
@@ -18,7 +18,7 @@ class TestGenerateExternalIds(TestCase):
Test generating ExternalIDs for Users.
"""
def setUp(self):
super(TestGenerateExternalIds, self).setUp()
super(TestGenerateExternalIds, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.users = UserFactory.create_batch(10)
self.user_id_list = [user.id for user in self.users]
self.external_id_admin = ExternalIdAdmin(ExternalId, AdminSite())

View File

@@ -47,7 +47,7 @@ class MicrobachelorsExternalIDTest(ModuleStoreTestCase, CacheIsolationTestCase):
)
def setUp(self):
super(MicrobachelorsExternalIDTest, self).setUp()
super(MicrobachelorsExternalIDTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
RequestCache.clear_all_namespaces()
self.program = self._create_cached_program()
self.client.login(username=self.user.username, password=TEST_PASSWORD)

View File

@@ -19,7 +19,7 @@ class CountryMiddlewareTests(TestCase):
Tests of CountryMiddleware.
"""
def setUp(self):
super(CountryMiddlewareTests, self).setUp()
super(CountryMiddlewareTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.country_middleware = CountryMiddleware()
self.session_middleware = SessionMiddleware()
self.authenticated_user = UserFactory.create()