From 7be5a683aabd2743dde8ad2a568431d7ffb277b7 Mon Sep 17 00:00:00 2001 From: Jawayria Date: Tue, 2 Feb 2021 14:44:17 +0500 Subject: [PATCH] Applied pylint-amnesty to third_party_auth --- .../djangoapps/third_party_auth/__init__.py | 2 +- common/djangoapps/third_party_auth/admin.py | 6 +-- .../third_party_auth/api/serializers.py | 2 +- .../api/tests/test_permissions.py | 4 +- .../third_party_auth/api/tests/test_views.py | 4 +- .../djangoapps/third_party_auth/api/views.py | 8 ++-- common/djangoapps/third_party_auth/apps.py | 4 +- .../djangoapps/third_party_auth/decorators.py | 6 +-- common/djangoapps/third_party_auth/lti.py | 2 +- .../commands/remove_social_auth_users.py | 4 +- .../tests/test_remove_social_auth_users.py | 4 +- .../management/commands/tests/test_saml.py | 4 +- .../djangoapps/third_party_auth/middleware.py | 4 +- common/djangoapps/third_party_auth/models.py | 12 ++--- .../djangoapps/third_party_auth/pipeline.py | 18 +++---- common/djangoapps/third_party_auth/saml.py | 22 ++++----- .../tests/test_saml_configuration.py | 8 ++-- .../samlproviderconfig/serializers.py | 2 +- .../samlproviderconfig/views.py | 2 +- .../samlproviderdata/views.py | 2 +- .../djangoapps/third_party_auth/strategy.py | 2 +- common/djangoapps/third_party_auth/tasks.py | 8 ++-- .../third_party_auth/tests/specs/base.py | 10 ++-- .../tests/specs/test_azuread.py | 4 +- .../tests/specs/test_generic.py | 4 +- .../tests/specs/test_google.py | 6 +-- .../tests/specs/test_linkedin.py | 4 +- .../third_party_auth/tests/specs/test_lti.py | 4 +- .../tests/specs/test_testshib.py | 48 +++++++++---------- .../tests/specs/test_twitter.py | 6 +-- .../third_party_auth/tests/test_admin.py | 2 +- .../third_party_auth/tests/test_decorators.py | 6 +-- .../tests/test_identityserver3.py | 4 +- .../third_party_auth/tests/test_pipeline.py | 4 +- .../tests/test_pipeline_integration.py | 30 ++++++------ .../third_party_auth/tests/test_provider.py | 4 +- .../third_party_auth/tests/test_settings.py | 4 +- .../third_party_auth/tests/test_views.py | 2 +- .../third_party_auth/tests/testutil.py | 10 ++-- .../third_party_auth/tests/utils.py | 6 +-- common/djangoapps/third_party_auth/utils.py | 4 +- common/djangoapps/third_party_auth/views.py | 2 +- 42 files changed, 147 insertions(+), 147 deletions(-) diff --git a/common/djangoapps/third_party_auth/__init__.py b/common/djangoapps/third_party_auth/__init__.py index dcc2964a8f..3535e709f3 100644 --- a/common/djangoapps/third_party_auth/__init__.py +++ b/common/djangoapps/third_party_auth/__init__.py @@ -1,4 +1,4 @@ -"""Third party authentication. """ +"""Third party authentication. """ # lint-amnesty, pylint: disable=django-not-configured from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers diff --git a/common/djangoapps/third_party_auth/admin.py b/common/djangoapps/third_party_auth/admin.py index 305b0daef7..df0f4fae3d 100644 --- a/common/djangoapps/third_party_auth/admin.py +++ b/common/djangoapps/third_party_auth/admin.py @@ -56,7 +56,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin): """ Filter the queryset to exclude the archived records. """ - queryset = super(SAMLProviderConfigAdmin, self).get_queryset(request).exclude(archived=True) + queryset = super(SAMLProviderConfigAdmin, self).get_queryset(request).exclude(archived=True) # lint-amnesty, pylint: disable=super-with-arguments return queryset def archive_provider_configuration(self, request, queryset): @@ -81,7 +81,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin): """ Get the actions. """ - actions = super(SAMLProviderConfigAdmin, self).get_actions(request) + actions = super(SAMLProviderConfigAdmin, self).get_actions(request) # lint-amnesty, pylint: disable=super-with-arguments action_delete = { 'archive_provider_configuration': ( SAMLProviderConfigAdmin.archive_provider_configuration, @@ -128,7 +128,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin): Note: This only works if the celery worker and the app worker are using the same 'configuration' cache. """ - super(SAMLProviderConfigAdmin, self).save_model(request, obj, form, change) + super(SAMLProviderConfigAdmin, self).save_model(request, obj, form, change) # lint-amnesty, pylint: disable=super-with-arguments fetch_saml_metadata.apply_async((), countdown=2) admin.site.register(SAMLProviderConfig, SAMLProviderConfigAdmin) diff --git a/common/djangoapps/third_party_auth/api/serializers.py b/common/djangoapps/third_party_auth/api/serializers.py index e4c9398c70..4a4eaa88e4 100644 --- a/common/djangoapps/third_party_auth/api/serializers.py +++ b/common/djangoapps/third_party_auth/api/serializers.py @@ -12,7 +12,7 @@ class UserMappingSerializer(serializers.Serializer): # pylint: disable=abstract def __init__(self, *args, **kwargs): self.provider = kwargs['context'].get('provider', None) - super(UserMappingSerializer, self).__init__(*args, **kwargs) + super(UserMappingSerializer, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def get_username(self, social_user): """ Gets the edx username from a social user """ diff --git a/common/djangoapps/third_party_auth/api/tests/test_permissions.py b/common/djangoapps/third_party_auth/api/tests/test_permissions.py index 89f13f5bbb..cc4d00c3e4 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_permissions.py +++ b/common/djangoapps/third_party_auth/api/tests/test_permissions.py @@ -10,7 +10,7 @@ from django.conf import settings from django.test import RequestFactory, TestCase from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.jwt.tests.utils import generate_jwt -from mock import patch +from mock import patch # lint-amnesty, pylint: disable=unused-import from rest_framework.authentication import SessionAuthentication from rest_framework.response import Response from rest_framework.views import APIView @@ -33,7 +33,7 @@ class ThirdPartyAuthPermissionTest(TestCase): permission_classes = (TPA_PERMISSIONS,) required_scopes = ['tpa:read'] - def get(self, request, provider_id=None): + def get(self, request, provider_id=None): # lint-amnesty, pylint: disable=unused-argument return Response(data="Success") def _create_user(self, is_superuser=False, is_staff=False): diff --git a/common/djangoapps/third_party_auth/api/tests/test_views.py b/common/djangoapps/third_party_auth/api/tests/test_views.py index 3f05e01d29..ed138d4fec 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_views.py +++ b/common/djangoapps/third_party_auth/api/tests/test_views.py @@ -49,7 +49,7 @@ class TpaAPITestCase(ThirdPartyAuthTestMixin, APITestCase): def setUp(self): # pylint: disable=arguments-differ """ Create users for use in the tests """ - super(TpaAPITestCase, self).setUp() + super(TpaAPITestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments google = self.configure_google_provider(enabled=True) self.configure_facebook_provider(enabled=True) @@ -364,7 +364,7 @@ class TestThirdPartyAuthUserStatusView(ThirdPartyAuthTestMixin, APITestCase): """ def setUp(self, *args, **kwargs): - super(TestThirdPartyAuthUserStatusView, self).setUp(*args, **kwargs) + super(TestThirdPartyAuthUserStatusView, self).setUp(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create(password=PASSWORD) self.google_provider = self.configure_google_provider(enabled=True, visible=True) self.url = reverse('third_party_auth_user_status_api') diff --git a/common/djangoapps/third_party_auth/api/views.py b/common/djangoapps/third_party_auth/api/views.py index 7b0ab3469c..165f18536f 100644 --- a/common/djangoapps/third_party_auth/api/views.py +++ b/common/djangoapps/third_party_auth/api/views.py @@ -6,7 +6,7 @@ Third Party Auth REST API views from collections import namedtuple 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.db.models import Q from django.http import Http404 from django.urls import reverse @@ -40,7 +40,7 @@ class ProviderBaseThrottle(throttling.UserRateThrottle): Only throttle unprivileged requests. """ if view.is_unprivileged_query(request, view.get_identifier_for_requested_user(request)): - return super(ProviderBaseThrottle, self).allow_request(request, view) + return super(ProviderBaseThrottle, self).allow_request(request, view) # lint-amnesty, pylint: disable=super-with-arguments return True @@ -175,7 +175,7 @@ class UserView(BaseUserView): login. """ - def get(self, request, username): + def get(self, request, username): # lint-amnesty, pylint: disable=unused-argument """Read provider information for a user. Allows reading the list of providers for a specified user. @@ -378,7 +378,7 @@ class UserMappingView(ListAPIView): Extra context provided to the serializer class with current provider. We need the provider to remove idp_slug from the remote_id if there is any """ - context = super(UserMappingView, self).get_serializer_context() + context = super(UserMappingView, self).get_serializer_context() # lint-amnesty, pylint: disable=super-with-arguments context['provider'] = self.provider return context diff --git a/common/djangoapps/third_party_auth/apps.py b/common/djangoapps/third_party_auth/apps.py index be657e35a3..1efe8ff0ed 100644 --- a/common/djangoapps/third_party_auth/apps.py +++ b/common/djangoapps/third_party_auth/apps.py @@ -1,10 +1,10 @@ - + # lint-amnesty, pylint: disable=missing-module-docstring from django.apps import AppConfig from django.conf import settings -class ThirdPartyAuthConfig(AppConfig): +class ThirdPartyAuthConfig(AppConfig): # lint-amnesty, pylint: disable=missing-class-docstring name = 'common.djangoapps.third_party_auth' verbose_name = "Third-party authentication" diff --git a/common/djangoapps/third_party_auth/decorators.py b/common/djangoapps/third_party_auth/decorators.py index 3f79bb4dae..0ac563d902 100644 --- a/common/djangoapps/third_party_auth/decorators.py +++ b/common/djangoapps/third_party_auth/decorators.py @@ -6,12 +6,12 @@ Decorators that can be used to interact with third_party_auth. from functools import wraps from django.conf import settings -from django.shortcuts import redirect +from django.shortcuts import redirect # lint-amnesty, pylint: disable=unused-import from django.utils.decorators import available_attrs -from six.moves.urllib.parse import urlencode, urlparse +from six.moves.urllib.parse import urlencode, urlparse # lint-amnesty, pylint: disable=unused-import from common.djangoapps.third_party_auth.models import LTIProviderConfig -from common.djangoapps.third_party_auth.provider import Registry +from common.djangoapps.third_party_auth.provider import Registry # lint-amnesty, pylint: disable=unused-import def xframe_allow_whitelisted(view_func): diff --git a/common/djangoapps/third_party_auth/lti.py b/common/djangoapps/third_party_auth/lti.py index 05c0d71a5e..d33abe686d 100644 --- a/common/djangoapps/third_party_auth/lti.py +++ b/common/djangoapps/third_party_auth/lti.py @@ -51,7 +51,7 @@ class LTIAuthBackend(BaseAuth): # Set a auth_entry here so we don't have to receive that as a custom parameter self.strategy.session_setdefault('auth_entry', 'login') - if not validated_lti_params: + if not validated_lti_params: # lint-amnesty, pylint: disable=no-else-raise self.strategy.session_set(LTI_PARAMS_KEY, None) raise AuthFailed(self, "LTI parameters could not be validated.") else: diff --git a/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py b/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py index 406044fc72..4858ca4d93 100644 --- a/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py +++ b/common/djangoapps/third_party_auth/management/commands/remove_social_auth_users.py @@ -7,7 +7,7 @@ integration sandboxes to allow partners reset users and enrollment data. import logging 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.core.management.base import BaseCommand, CommandError from django.db import transaction from six.moves import input @@ -45,7 +45,7 @@ class Command(BaseCommand): try: SAMLProviderConfig.objects.current_set().get(slug=slug) except SAMLProviderConfig.DoesNotExist: - raise CommandError(u'No SAML provider found for slug {}'.format(slug)) + raise CommandError(u'No SAML provider found for slug {}'.format(slug)) # lint-amnesty, pylint: disable=raise-missing-from users = User.objects.filter(social_auth__provider=slug) user_count = len(users) diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py b/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py index ddd75d23d2..8b5b4d4fd1 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_remove_social_auth_users.py @@ -35,7 +35,7 @@ class TestRemoveSocialAuthUsersCommand(TestCase): cls.command = remove_social_auth_users.Command() def setUp(self): - super(TestRemoveSocialAuthUsersCommand, self).setUp() + super(TestRemoveSocialAuthUsersCommand, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.provider_hogwarts = SAMLProviderConfigFactory.create(slug='hogwarts') self.provider_durmstrang = SAMLProviderConfigFactory.create(slug='durmstrang') @@ -47,7 +47,7 @@ class TestRemoveSocialAuthUsersCommand(TestCase): self.create_social_auth_entry(self.user_viktor, self.provider_durmstrang) @contextmanager - def _replace_stdin(self, text): + def _replace_stdin(self, text): # lint-amnesty, pylint: disable=missing-function-docstring orig = sys.stdin sys.stdin = StringIO(text) yield diff --git a/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py b/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py index 46144f3b04..1d65a215ea 100644 --- a/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py +++ b/common/djangoapps/third_party_auth/management/commands/tests/test_saml.py @@ -27,7 +27,7 @@ def mock_get(status_code=200): Returns: returns a function that can be used as a mock function for requests.get. """ - def _(url=None, *args, **kwargs): # pylint: disable=unused-argument + def _(url=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg, unused-argument """ mock method for requests.get, this method will read xml file, form a Response object from the contents of this file, set status code and return the Response object. @@ -56,7 +56,7 @@ class TestSAMLCommand(CacheIsolationTestCase): Setup operations for saml configurations. these operations contain creation of SAMLConfiguration and SAMLProviderConfig records in database. """ - super(TestSAMLCommand, self).setUp() + super(TestSAMLCommand, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.stdout = StringIO() diff --git a/common/djangoapps/third_party_auth/middleware.py b/common/djangoapps/third_party_auth/middleware.py index 0023ee36c0..b623dec2ee 100644 --- a/common/djangoapps/third_party_auth/middleware.py +++ b/common/djangoapps/third_party_auth/middleware.py @@ -20,7 +20,7 @@ class ExceptionMiddleware(SocialAuthExceptionMiddleware, MiddlewareMixin): def get_redirect_uri(self, request, exception): # Fall back to django settings's SOCIAL_AUTH_LOGIN_ERROR_URL. - redirect_uri = super(ExceptionMiddleware, self).get_redirect_uri(request, exception) + redirect_uri = super(ExceptionMiddleware, self).get_redirect_uri(request, exception) # lint-amnesty, pylint: disable=super-with-arguments # Safe because it's already been validated by # pipeline.parse_query_params. If that pipeline step ever moves later @@ -48,4 +48,4 @@ class ExceptionMiddleware(SocialAuthExceptionMiddleware, MiddlewareMixin): redirect_url = get_next_url_for_login_page(request) return redirect('/login?next=' + redirect_url) - return super(ExceptionMiddleware, self).process_exception(request, exception) + return super(ExceptionMiddleware, self).process_exception(request, exception) # lint-amnesty, pylint: disable=super-with-arguments diff --git a/common/djangoapps/third_party_auth/models.py b/common/djangoapps/third_party_auth/models.py index c8f2fa20fa..f00da2c1fc 100644 --- a/common/djangoapps/third_party_auth/models.py +++ b/common/djangoapps/third_party_auth/models.py @@ -60,7 +60,7 @@ def clean_json(value, of_type): try: value_python = json.loads(value) except ValueError as err: - raise ValidationError(u"Invalid JSON: {}".format(err)) + raise ValidationError(u"Invalid JSON: {}".format(err)) # lint-amnesty, pylint: disable=raise-missing-from if not isinstance(value_python, of_type): raise ValidationError(u"Expected a JSON {}".format(of_type)) return json.dumps(value_python, indent=4) @@ -74,7 +74,7 @@ def clean_username(username=''): class AuthNotConfigured(SocialAuthBaseException): """ Exception when SAMLProviderData or other required info is missing """ def __init__(self, provider_name): - super(AuthNotConfigured, self).__init__() + super(AuthNotConfigured, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments self.provider_name = provider_name def __str__(self): @@ -224,7 +224,7 @@ class ProviderConfig(ConfigurationModel): def clean(self): """ Ensure that at most `icon_class` or `icon_image` is set """ - super(ProviderConfig, self).clean() + super(ProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments if bool(self.icon_class) and bool(self.icon_image): raise ValidationError('Either an icon class or an icon image must be given (but not both)') @@ -379,7 +379,7 @@ class OAuth2ProviderConfig(ProviderConfig): def clean(self): """ Standardize and validate fields """ - super(OAuth2ProviderConfig, self).clean() + super(OAuth2ProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments self.other_settings = clean_json(self.other_settings, dict) def get_setting(self, name): @@ -483,7 +483,7 @@ class SAMLConfiguration(ConfigurationModel): def clean(self): """ Standardize and validate fields """ - super(SAMLConfiguration, self).clean() + super(SAMLConfiguration, self).clean() # lint-amnesty, pylint: disable=super-with-arguments self.org_info_str = clean_json(self.org_info_str, dict) self.other_config_str = clean_json(self.other_config_str, dict) @@ -686,7 +686,7 @@ class SAMLProviderConfig(ProviderConfig): def clean(self): """ Standardize and validate fields """ - super(SAMLProviderConfig, self).clean() + super(SAMLProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments self.other_settings = clean_json(self.other_settings, dict) class Meta(object): diff --git a/common/djangoapps/third_party_auth/pipeline.py b/common/djangoapps/third_party_auth/pipeline.py index 57b7e3a0b6..248055b5d2 100644 --- a/common/djangoapps/third_party_auth/pipeline.py +++ b/common/djangoapps/third_party_auth/pipeline.py @@ -70,7 +70,7 @@ from uuid import uuid4 import six import social_django 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.contrib.auth import logout from django.core.mail.message import EmailMessage from django.http import HttpResponseBadRequest @@ -141,7 +141,7 @@ BASE_URL = settings.AUTHN_MICROFRONTEND_URL if should_redirect_to_authn_microfro def is_api(auth_entry): """Returns whether the auth entry point is via an API call.""" - return (auth_entry == AUTH_ENTRY_LOGIN_API) or (auth_entry == AUTH_ENTRY_REGISTER_API) + return (auth_entry == AUTH_ENTRY_LOGIN_API) or (auth_entry == AUTH_ENTRY_REGISTER_API) # lint-amnesty, pylint: disable=consider-using-in # URLs associated with auth entry points # These are used to request additional user information @@ -550,7 +550,7 @@ def redirect_to_custom_form(request, auth_entry, details, kwargs): @partial.partial -def ensure_user_information(strategy, auth_entry, backend=None, user=None, social=None, current_partial=None, +def ensure_user_information(strategy, auth_entry, backend=None, user=None, social=None, current_partial=None, # lint-amnesty, pylint: disable=keyword-arg-before-vararg allow_inactive_user=False, details=None, *args, **kwargs): """ Ensure that we have the necessary information about a user (either an @@ -654,7 +654,7 @@ def ensure_user_information(strategy, auth_entry, backend=None, user=None, socia @partial.partial -def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=None, current_partial=None, +def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=None, current_partial=None, # lint-amnesty, pylint: disable=keyword-arg-before-vararg *args, **kwargs): """This pipeline step sets the "logged in" cookie for authenticated users. @@ -706,7 +706,7 @@ def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=Non @partial.partial -def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs): +def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg """ Sends login info to Segment """ event_name = None @@ -724,7 +724,7 @@ def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs) @partial.partial -def associate_by_email_if_login_api(auth_entry, backend, details, user, current_partial=None, *args, **kwargs): +def associate_by_email_if_login_api(auth_entry, backend, details, user, current_partial=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg """ This pipeline step associates the current social auth with the user with the same email address in the database. It defers to the social library's associate_by_email @@ -834,7 +834,7 @@ def associate_by_email_if_saml(auth_entry, backend, details, user, strategy, *ar return associate_response -def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **kwargs): +def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg """ Update normally protected user details using data from provider. @@ -921,7 +921,7 @@ def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **k u'notification email. Username: {username}'.format(username=user.username)) -def set_id_verification_status(auth_entry, strategy, details, user=None, *args, **kwargs): +def set_id_verification_status(auth_entry, strategy, details, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg """ Use the user's authentication with the provider, if configured, as evidence of their identity being verified. """ @@ -949,7 +949,7 @@ def set_id_verification_status(auth_entry, strategy, details, user=None, *args, verification.send_approval_signal(current_provider.slug) -def get_username(strategy, details, backend, user=None, *args, **kwargs): +def get_username(strategy, details, backend, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg """ Copy of social_core.pipeline.user.get_username to achieve 1. additional logging diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index 44960b3b78..7d7cfdcbcc 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -83,23 +83,23 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method config["sp"].update(self.get_idp_setting(idp, "SP_EXTRA", {})) return config else: - return super(SAMLAuthBackend, self).generate_saml_config() + return super(SAMLAuthBackend, self).generate_saml_config() # lint-amnesty, pylint: disable=super-with-arguments def get_user_id(self, details, response): """ Calling the parent function and handling the exception properly. """ try: - return super(SAMLAuthBackend, self).get_user_id(details, response) + return super(SAMLAuthBackend, self).get_user_id(details, response) # lint-amnesty, pylint: disable=super-with-arguments except KeyError as ex: log.warning( u'[THIRD_PARTY_AUTH] Error in SAML authentication flow. ' u'Provider: {idp_name}, Message: {message}'.format( - message=ex.message, + message=ex.message, # lint-amnesty, pylint: disable=no-member idp_name=response.get('idp_name') ) ) - raise IncorrectConfigurationException(self) + raise IncorrectConfigurationException(self) # lint-amnesty, pylint: disable=raise-missing-from def generate_metadata_xml(self, idp_name=None): # pylint: disable=arguments-differ """ @@ -127,7 +127,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method log.error('[THIRD_PARTY_AUTH] SAML authentication is not enabled') raise Http404 - return super(SAMLAuthBackend, self).auth_url() + return super(SAMLAuthBackend, self).auth_url() # lint-amnesty, pylint: disable=super-with-arguments def disconnect(self, *args, **kwargs): """ @@ -136,7 +136,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method from openedx.features.enterprise_support.api import unlink_enterprise_user_from_idp user = kwargs.get('user', None) unlink_enterprise_user_from_idp(self.strategy.request, user, self.name) - return super(SAMLAuthBackend, self).disconnect(*args, **kwargs) + return super(SAMLAuthBackend, self).disconnect(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def _check_entitlements(self, idp, attributes): """ @@ -165,7 +165,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method """ # We only override this method so that we can add extra debugging when debug_mode is True # Note that auth_inst is instantiated just for the current HTTP request, then is destroyed - auth_inst = super(SAMLAuthBackend, self)._create_saml_auth(idp) + auth_inst = super(SAMLAuthBackend, self)._create_saml_auth(idp) # lint-amnesty, pylint: disable=super-with-arguments from .models import SAMLProviderConfig if SAMLProviderConfig.current(idp.name).debug_mode: @@ -207,7 +207,7 @@ class EdXSAMLIdentityProvider(SAMLIdentityProvider): Overrides `get_user_details` from the base class; retrieves those details, then updates the dict with values from whatever additional fields are desired. """ - details = super(EdXSAMLIdentityProvider, self).get_user_details(attributes) + details = super(EdXSAMLIdentityProvider, self).get_user_details(attributes) # lint-amnesty, pylint: disable=super-with-arguments extra_field_definitions = self.conf.get('extra_field_definitions', []) details.update({ field['name']: attributes[field['urn']][0] if field['urn'] in attributes else None @@ -382,7 +382,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider): ) return missing - def log_bizx_api_exception(self, transaction_data, err): + def log_bizx_api_exception(self, transaction_data, err): # lint-amnesty, pylint: disable=missing-function-docstring try: sys_msg = err.response.content except AttributeError: @@ -476,7 +476,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider): return None return token_response.json() - def get_bizx_odata_api_client(self, user_id): + def get_bizx_odata_api_client(self, user_id): # lint-amnesty, pylint: disable=missing-function-docstring session = requests.Session() access_token_data = self.generate_bizx_oauth_api_access_token(user_id) if not access_token_data: @@ -492,7 +492,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider): of the info we need to do that, or if the request triggers an exception, then fail nicely by returning the basic user details we're able to extract from just the SAML response. """ - basic_details = super(SapSuccessFactorsIdentityProvider, self).get_user_details(attributes) + basic_details = super(SapSuccessFactorsIdentityProvider, self).get_user_details(attributes) # lint-amnesty, pylint: disable=super-with-arguments if self.invalid_configuration(): return basic_details user_id = basic_details['username'] diff --git a/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py b/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py index bf383d7d45..b42b5b2b97 100644 --- a/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py +++ b/common/djangoapps/third_party_auth/saml_configuration/tests/test_saml_configuration.py @@ -2,15 +2,15 @@ Tests for SAMLConfiguration endpoints """ -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from django.urls import reverse from django.contrib.sites.models import Site -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from rest_framework import status from rest_framework.test import APITestCase from common.djangoapps.third_party_auth.models import SAMLConfiguration -from common.djangoapps.third_party_auth.tests import testutil +from common.djangoapps.third_party_auth.tests import testutil # lint-amnesty, pylint: disable=unused-import from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth SAML_CONFIGURATIONS = [ { @@ -77,7 +77,7 @@ class SAMLConfigurationTests(APITestCase): ) def setUp(self): - super(SAMLConfigurationTests, self).setUp() + super(SAMLConfigurationTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.client.login(username=self.user.username, password=TEST_PASSWORD) def test_get_saml_configurations_successful(self): diff --git a/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py b/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py index 3e44d85a6c..def4909bea 100644 --- a/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py +++ b/common/djangoapps/third_party_auth/samlproviderconfig/serializers.py @@ -7,7 +7,7 @@ from rest_framework import serializers from common.djangoapps.third_party_auth.models import SAMLProviderConfig, SAMLConfiguration -class SAMLProviderConfigSerializer(serializers.ModelSerializer): +class SAMLProviderConfigSerializer(serializers.ModelSerializer): # lint-amnesty, pylint: disable=missing-class-docstring saml_config_id = serializers.IntegerField(required=False) class Meta: diff --git a/common/djangoapps/third_party_auth/samlproviderconfig/views.py b/common/djangoapps/third_party_auth/samlproviderconfig/views.py index 1b069443ca..050d655f21 100644 --- a/common/djangoapps/third_party_auth/samlproviderconfig/views.py +++ b/common/djangoapps/third_party_auth/samlproviderconfig/views.py @@ -95,7 +95,7 @@ class SAMLProviderConfigViewSet(PermissionRequiredMixin, SAMLProviderMixin, view try: enterprise_customer = EnterpriseCustomer.objects.get(pk=customer_uuid) except EnterpriseCustomer.DoesNotExist: - raise ValidationError('Enterprise customer not found at uuid: {}'.format(customer_uuid)) + raise ValidationError('Enterprise customer not found at uuid: {}'.format(customer_uuid)) # lint-amnesty, pylint: disable=raise-missing-from # Create the samlproviderconfig model first serializer = self.get_serializer(data=request.data) diff --git a/common/djangoapps/third_party_auth/samlproviderdata/views.py b/common/djangoapps/third_party_auth/samlproviderdata/views.py index 756fe8d7ca..e636018982 100644 --- a/common/djangoapps/third_party_auth/samlproviderdata/views.py +++ b/common/djangoapps/third_party_auth/samlproviderdata/views.py @@ -57,7 +57,7 @@ class SAMLProviderDataViewSet(PermissionRequiredMixin, SAMLProviderDataMixin, vi saml_provider = SAMLProviderConfig.objects.current_set().get( slug=convert_saml_slug_provider_id(enterprise_customer_idp.provider_id)) except SAMLProviderConfig.DoesNotExist: - raise Http404('No matching SAML provider found.') + raise Http404('No matching SAML provider found.') # lint-amnesty, pylint: disable=raise-missing-from return SAMLProviderData.objects.filter(entity_id=saml_provider.entity_id) @property diff --git a/common/djangoapps/third_party_auth/strategy.py b/common/djangoapps/third_party_auth/strategy.py index f578291b99..5bbe267894 100644 --- a/common/djangoapps/third_party_auth/strategy.py +++ b/common/djangoapps/third_party_auth/strategy.py @@ -57,4 +57,4 @@ class ConfigurationModelStrategy(DjangoStrategy): # At this point, we know 'name' is not set in a [OAuth2|LTI|SAML]ProviderConfig row. # It's probably a global Django setting like 'FIELDS_STORED_IN_SESSION': - return super(ConfigurationModelStrategy, self).setting(name, default, backend) + return super(ConfigurationModelStrategy, self).setting(name, default, backend) # lint-amnesty, pylint: disable=super-with-arguments diff --git a/common/djangoapps/third_party_auth/tasks.py b/common/djangoapps/third_party_auth/tasks.py index fed4579e48..1fb6560931 100644 --- a/common/djangoapps/third_party_auth/tasks.py +++ b/common/djangoapps/third_party_auth/tasks.py @@ -28,7 +28,7 @@ SAML_XML_NS = 'urn:oasis:names:tc:SAML:2.0:metadata' # The SAML Metadata XML na class MetadataParseError(Exception): """ An error occurred while parsing the SAML metadata from an IdP """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass @shared_task @@ -89,7 +89,7 @@ def fetch_saml_metadata(): try: parser = etree.XMLParser(remove_comments=True) xml = etree.fromstring(response.content, parser) - except etree.XMLSyntaxError: + except etree.XMLSyntaxError: # lint-amnesty, pylint: disable=try-except-raise raise # TODO: Can use OneLogin_Saml2_Utils to validate signed XML if anyone is using that @@ -125,7 +125,7 @@ def fetch_saml_metadata(): log.exception(text_type(error)) failure_messages.append( u"XMLSyntaxError: {error_message}\nMetadata Source: {url}\nEntity IDs: \n{entity_ids}.".format( - error_message=str(error.error_log), + error_message=str(error.error_log), # lint-amnesty, pylint: disable=no-member url=url, entity_ids="\n".join( [u"\t{}: {}".format(count, item) for count, item in enumerate(entity_ids, start=1)], @@ -183,7 +183,7 @@ def _parse_metadata_xml(xml, entity_id): # The only binding supported by python-saml and python-social-auth is HTTP-Redirect: sso_url = sso_bindings['urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'] except KeyError: - raise MetadataParseError("Unable to find SSO URL with HTTP-Redirect binding.") + raise MetadataParseError("Unable to find SSO URL with HTTP-Redirect binding.") # lint-amnesty, pylint: disable=raise-missing-from return public_key, sso_url, expires_at diff --git a/common/djangoapps/third_party_auth/tests/specs/base.py b/common/djangoapps/third_party_auth/tests/specs/base.py index 685341ce81..faaea58cf7 100644 --- a/common/djangoapps/third_party_auth/tests/specs/base.py +++ b/common/djangoapps/third_party_auth/tests/specs/base.py @@ -16,7 +16,7 @@ from django.contrib.messages.storage import fallback from django.contrib.sessions.backends import cache from django.urls import reverse from django.test import utils as django_utils -from django.conf import settings as django_settings +from django.conf import settings as django_settings # lint-amnesty, pylint: disable=reimported from social_core import actions, exceptions from social_django import utils as social_utils from social_django import views as social_views @@ -58,7 +58,7 @@ class HelperMixin(object): self.assertEqual(302, response.status_code) self.assertTrue(response.has_header('Location')) - def assert_register_response_in_pipeline_looks_correct(self, response, pipeline_kwargs, required_fields): + def assert_register_response_in_pipeline_looks_correct(self, response, pipeline_kwargs, required_fields): # lint-amnesty, pylint: disable=invalid-name """Performs spot checks of the rendered register.html page. When we display the new account registration form after the user signs @@ -366,7 +366,7 @@ class IntegrationTestMixin(testutil.TestCase, test.TestCase, HelperMixin): USER_USERNAME = "override" def setUp(self): - super(IntegrationTestMixin, self).setUp() + super(IntegrationTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.request_factory = test.RequestFactory() self.login_page_url = reverse('signin_user') @@ -536,7 +536,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin): """Abstract base class for provider integration tests.""" def setUp(self): - super(IntegrationTest, self).setUp() + super(IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.request_factory = test.RequestFactory() # Actual tests, executed once per child. @@ -1023,7 +1023,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin): # pylint: disable=abstract-method @django_utils.override_settings(ECOMMERCE_API_URL=TEST_API_URL) -class Oauth2IntegrationTest(IntegrationTest): +class Oauth2IntegrationTest(IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests """Base test case for integration tests of Oauth2 providers.""" # Dict of string -> object. Information about the token granted to the diff --git a/common/djangoapps/third_party_auth/tests/specs/test_azuread.py b/common/djangoapps/third_party_auth/tests/specs/test_azuread.py index c7967aa2e2..e980b5da04 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_azuread.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_azuread.py @@ -4,11 +4,11 @@ from common.djangoapps.third_party_auth.tests.specs import base -class AzureADOauth2IntegrationTest(base.Oauth2IntegrationTest): +class AzureADOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests """Integration tests for Azure Active Directory / Microsoft Account provider.""" def setUp(self): - super(AzureADOauth2IntegrationTest, self).setUp() + super(AzureADOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.provider = self.configure_azure_ad_provider( enabled=True, visible=True, diff --git a/common/djangoapps/third_party_auth/tests/specs/test_generic.py b/common/djangoapps/third_party_auth/tests/specs/test_generic.py index 7fb37b4d15..e896700b6e 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_generic.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_generic.py @@ -3,7 +3,7 @@ Use the 'Dummy' auth provider for generic integration tests of third_party_auth. """ -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth from .base import IntegrationTestMixin @@ -23,7 +23,7 @@ class GenericIntegrationTest(IntegrationTestMixin, testutil.TestCase): USER_USERNAME = "Galactica1" def setUp(self): - super(GenericIntegrationTest, self).setUp() + super(GenericIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.configure_dummy_provider(enabled=True, visible=True) def do_provider_login(self, provider_redirect_url): diff --git a/common/djangoapps/third_party_auth/tests/specs/test_google.py b/common/djangoapps/third_party_auth/tests/specs/test_google.py index 6d21542681..1941481cde 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_google.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_google.py @@ -16,11 +16,11 @@ from common.djangoapps.third_party_auth import pipeline from common.djangoapps.third_party_auth.tests.specs import base -class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest): +class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests """Integration tests for provider.GoogleOauth2.""" def setUp(self): - super(GoogleOauth2IntegrationTest, self).setUp() + super(GoogleOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.provider = self.configure_google_provider( enabled=True, visible=True, @@ -50,7 +50,7 @@ class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest): return self.get_response_data().get('email').split('@')[0] def assert_redirect_to_provider_looks_correct(self, response): - super(GoogleOauth2IntegrationTest, self).assert_redirect_to_provider_looks_correct(response) + super(GoogleOauth2IntegrationTest, self).assert_redirect_to_provider_looks_correct(response) # lint-amnesty, pylint: disable=super-with-arguments self.assertIn('google.com', response['Location']) def test_custom_form(self): diff --git a/common/djangoapps/third_party_auth/tests/specs/test_linkedin.py b/common/djangoapps/third_party_auth/tests/specs/test_linkedin.py index 6c6b7dcdcf..9a48ac0f59 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_linkedin.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_linkedin.py @@ -13,11 +13,11 @@ def get_localized_name(name): return name['localized'].get(locale, '') -class LinkedInOauth2IntegrationTest(base.Oauth2IntegrationTest): +class LinkedInOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests """Integration tests for provider.LinkedInOauth2.""" def setUp(self): - super(LinkedInOauth2IntegrationTest, self).setUp() + super(LinkedInOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.provider = self.configure_linkedin_provider( enabled=True, visible=True, diff --git a/common/djangoapps/third_party_auth/tests/specs/test_lti.py b/common/djangoapps/third_party_auth/tests/specs/test_lti.py index 811be51963..4547604cb1 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_lti.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_lti.py @@ -5,7 +5,7 @@ Integration tests for third_party_auth LTI auth providers import unittest 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 oauthlib.oauth1.rfc5849 import Client, SIGNATURE_TYPE_BODY from common.djangoapps.third_party_auth.tests import testutil @@ -30,7 +30,7 @@ class IntegrationTestLTI(testutil.TestCase): """ def setUp(self): - super(IntegrationTestLTI, self).setUp() + super(IntegrationTestLTI, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.hostname = 'testserver' self.client.defaults['SERVER_NAME'] = self.hostname self.url_prefix = 'http://{}'.format(self.hostname) diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index a3c228effb..8d63f7206f 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -7,7 +7,7 @@ import datetime import json import logging import os -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from unittest import skip import ddt @@ -53,27 +53,27 @@ class SamlIntegrationTestUtilities(object): USER_USERNAME = "myself" def setUp(self): - super(SamlIntegrationTestUtilities, self).setUp() - self.enable_saml( - private_key=self._get_private_key(), - public_key=self._get_public_key(), + super(SamlIntegrationTestUtilities, self).setUp() # lint-amnesty, pylint: disable=no-member, super-with-arguments + self.enable_saml( # lint-amnesty, pylint: disable=no-member + private_key=self._get_private_key(), # lint-amnesty, pylint: disable=no-member + public_key=self._get_public_key(), # lint-amnesty, pylint: disable=no-member entity_id="https://saml.example.none", ) # Mock out HTTP requests that may be made to TestShib: httpretty.enable() httpretty.reset() - self.addCleanup(httpretty.reset) - self.addCleanup(httpretty.disable) + self.addCleanup(httpretty.reset) # lint-amnesty, pylint: disable=no-member + self.addCleanup(httpretty.disable) # lint-amnesty, pylint: disable=no-member def metadata_callback(_request, _uri, headers): """ Return a cached copy of TestShib's metadata by reading it from disk """ - return (200, headers, self.read_data_file('testshib_metadata.xml')) + return (200, headers, self.read_data_file('testshib_metadata.xml')) # lint-amnesty, pylint: disable=no-member httpretty.register_uri(httpretty.GET, TESTSHIB_METADATA_URL, content_type='text/xml', body=metadata_callback) def cache_duration_metadata_callback(_request, _uri, headers): """Return a cached copy of TestShib's metadata with a cacheDuration attribute""" - return (200, headers, self.read_data_file('testshib_metadata_with_cache_duration.xml')) + return (200, headers, self.read_data_file('testshib_metadata_with_cache_duration.xml')) # lint-amnesty, pylint: disable=no-member httpretty.register_uri( httpretty.GET, @@ -86,14 +86,14 @@ class SamlIntegrationTestUtilities(object): # Doing this and freezing the time allows us to play back recorded request/response pairs uid_patch = patch('onelogin.saml2.utils.OneLogin_Saml2_Utils.generate_unique_id', return_value='TESTID') uid_patch.start() - self.addCleanup(uid_patch.stop) + self.addCleanup(uid_patch.stop) # lint-amnesty, pylint: disable=no-member self._freeze_time(timestamp=1434326820) # This is the time when the saved request/response was recorded. def _freeze_time(self, timestamp): """ Mock the current time for SAML, so we can replay canned requests/responses """ now_patch = patch('onelogin.saml2.utils.OneLogin_Saml2_Utils.now', return_value=timestamp) now_patch.start() - self.addCleanup(now_patch.stop) + self.addCleanup(now_patch.stop) # lint-amnesty, pylint: disable=no-member def _configure_testshib_provider(self, **kwargs): """ Enable and configure the TestShib SAML IdP as a third_party_auth provider """ @@ -114,28 +114,28 @@ class SamlIntegrationTestUtilities(object): saml_provider = self.configure_saml_provider(**kwargs) # pylint: disable=no-member if fetch_metadata: - self.assertTrue(httpretty.is_enabled()) + self.assertTrue(httpretty.is_enabled()) # lint-amnesty, pylint: disable=no-member num_total, num_skipped, num_attempted, num_updated, num_failed, failure_messages = fetch_saml_metadata() if assert_metadata_updates: - self.assertEqual(num_total, 1) - self.assertEqual(num_skipped, 0) - self.assertEqual(num_attempted, 1) - self.assertEqual(num_updated, 1) - self.assertEqual(num_failed, 0) - self.assertEqual(len(failure_messages), 0) + self.assertEqual(num_total, 1) # lint-amnesty, pylint: disable=no-member + self.assertEqual(num_skipped, 0) # lint-amnesty, pylint: disable=no-member + self.assertEqual(num_attempted, 1) # lint-amnesty, pylint: disable=no-member + self.assertEqual(num_updated, 1) # lint-amnesty, pylint: disable=no-member + self.assertEqual(num_failed, 0) # lint-amnesty, pylint: disable=no-member + self.assertEqual(len(failure_messages), 0) # lint-amnesty, pylint: disable=no-member return saml_provider def do_provider_login(self, provider_redirect_url): """ Mocked: the user logs in to TestShib and then gets redirected back """ # The SAML provider (TestShib) will authenticate the user, then get the browser to POST a response: - self.assertTrue(provider_redirect_url.startswith(TESTSHIB_SSO_URL)) + self.assertTrue(provider_redirect_url.startswith(TESTSHIB_SSO_URL)) # lint-amnesty, pylint: disable=no-member saml_response_xml = utils.read_and_pre_process_xml( os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'testshib_saml_response.xml') ) - return self.client.post( - self.complete_url, + return self.client.post( # lint-amnesty, pylint: disable=no-member + self.complete_url, # lint-amnesty, pylint: disable=no-member content_type='application/x-www-form-urlencoded', data=utils.prepare_saml_response_from_xml(saml_response_xml), ) @@ -188,7 +188,7 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin enterprise_customer = EnterpriseCustomerFactory() assert EnterpriseCustomerUser.objects.count() == 0, "Precondition check: no link records should exist" EnterpriseCustomerUser.objects.link_user(enterprise_customer, user.email) - self.assertTrue( + self.assertTrue( # lint-amnesty, pylint: disable=wrong-assert-type EnterpriseCustomerUser.objects.filter(enterprise_customer=enterprise_customer, user_id=user.id).count() == 1 ) EnterpriseCustomerIdentityProvider.objects.get_or_create(enterprise_customer=enterprise_customer, @@ -394,7 +394,7 @@ class SuccessFactorsIntegrationTest(SamlIntegrationTestUtilities, IntegrationTes """ Mock out HTTP calls to various endpoints using httpretty. """ - super(SuccessFactorsIntegrationTest, self).setUp() + super(SuccessFactorsIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Mock the call to the SAP SuccessFactors assertion endpoint SAPSF_ASSERTION_URL = 'http://successfactors.com/oauth/idp' @@ -467,7 +467,7 @@ class SuccessFactorsIntegrationTest(SamlIntegrationTestUtilities, IntegrationTes Mock an error response when calling the OData API for user details. """ - def callback(request, uri, headers): + def callback(request, uri, headers): # lint-amnesty, pylint: disable=unused-argument """ Return a 500 error when someone tries to call the URL. """ diff --git a/common/djangoapps/third_party_auth/tests/specs/test_twitter.py b/common/djangoapps/third_party_auth/tests/specs/test_twitter.py index e4e43f283a..c602c11a02 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_twitter.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_twitter.py @@ -1,4 +1,4 @@ -""" +""" # lint-amnesty, pylint: disable=cyclic-import Separate integration test for Twitter which is an OAuth1 provider. """ @@ -7,11 +7,11 @@ from mock import patch from common.djangoapps.third_party_auth.tests.specs import base -class TwitterIntegrationTest(base.Oauth2IntegrationTest): +class TwitterIntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests """Integration tests for Twitter backend.""" def setUp(self): - super(TwitterIntegrationTest, self).setUp() + super(TwitterIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.provider = self.configure_twitter_provider( enabled=True, visible=True, diff --git a/common/djangoapps/third_party_auth/tests/test_admin.py b/common/djangoapps/third_party_auth/tests/test_admin.py index 63ad2bf8cb..e830a8259a 100644 --- a/common/djangoapps/third_party_auth/tests/test_admin.py +++ b/common/djangoapps/third_party_auth/tests/test_admin.py @@ -3,7 +3,7 @@ Tests third_party_auth admin views """ -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from django.contrib.admin.sites import AdminSite from django.core.files.uploadedfile import SimpleUploadedFile diff --git a/common/djangoapps/third_party_auth/tests/test_decorators.py b/common/djangoapps/third_party_auth/tests/test_decorators.py index b7cb5ea1a9..972cfafd00 100644 --- a/common/djangoapps/third_party_auth/tests/test_decorators.py +++ b/common/djangoapps/third_party_auth/tests/test_decorators.py @@ -3,10 +3,10 @@ Tests for third_party_auth decorators. """ -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import import ddt -from django.conf import settings +from django.conf import settings # lint-amnesty, pylint: disable=unused-import from django.http import HttpResponse from django.test import RequestFactory @@ -27,7 +27,7 @@ class TestXFrameWhitelistDecorator(TestCase): """ Test the xframe_allow_whitelisted decorator. """ def setUp(self): - super(TestXFrameWhitelistDecorator, self).setUp() + super(TestXFrameWhitelistDecorator, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.configure_lti_provider(name='Test', lti_hostname='localhost', lti_consumer_key='test_key', enabled=True) self.factory = RequestFactory() diff --git a/common/djangoapps/third_party_auth/tests/test_identityserver3.py b/common/djangoapps/third_party_auth/tests/test_identityserver3.py index 1eabc7fd2c..923adf9f6a 100644 --- a/common/djangoapps/third_party_auth/tests/test_identityserver3.py +++ b/common/djangoapps/third_party_auth/tests/test_identityserver3.py @@ -3,7 +3,7 @@ Unit tests for the IdentityServer3 OAuth2 Backend """ import json import ddt -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import, wrong-import-order from common.djangoapps.third_party_auth.identityserver3 import IdentityServer3 from common.djangoapps.third_party_auth.tests import testutil from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth @@ -17,7 +17,7 @@ class IdentityServer3Test(testutil.TestCase): """ def setUp(self): - super(IdentityServer3Test, self).setUp() + super(IdentityServer3Test, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.id3_instance = IdentityServer3() self.response = { "sub": "020cadec-919a-4b06-845e-57915bf76826", diff --git a/common/djangoapps/third_party_auth/tests/test_pipeline.py b/common/djangoapps/third_party_auth/tests/test_pipeline.py index 876ae969f9..d4713a68a6 100644 --- a/common/djangoapps/third_party_auth/tests/test_pipeline.py +++ b/common/djangoapps/third_party_auth/tests/test_pipeline.py @@ -2,7 +2,7 @@ import json -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import import ddt import mock @@ -63,7 +63,7 @@ class PipelineOverridesTest(SamlIntegrationTestUtilities, IntegrationTestMixin, """ def setUp(self): - super(PipelineOverridesTest, self).setUp() + super(PipelineOverridesTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.enable_saml() self.provider = self.configure_saml_provider( enabled=True, diff --git a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py index a182a669d9..051ce9d13d 100644 --- a/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py +++ b/common/djangoapps/third_party_auth/tests/test_pipeline_integration.py @@ -2,7 +2,7 @@ import datetime -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import import ddt import mock @@ -27,7 +27,7 @@ class TestCase(testutil.TestCase, test.TestCase): """Base test case.""" def setUp(self): - super(TestCase, self).setUp() + super(TestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.enabled_provider = self.configure_google_provider(enabled=True) @@ -35,7 +35,7 @@ class GetAuthenticatedUserTestCase(TestCase): """Tests for get_authenticated_user.""" def setUp(self): - super(GetAuthenticatedUserTestCase, self).setUp() + super(GetAuthenticatedUserTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = social_models.DjangoStorage.user.create_user(username='username', password='password') def get_by_username(self, username): @@ -75,7 +75,7 @@ class GetProviderUserStatesTestCase(TestCase): """Tests generation of ProviderUserStates.""" def setUp(self): - super(GetProviderUserStatesTestCase, self).setUp() + super(GetProviderUserStatesTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.configure_google_provider(enabled=False) self.user = social_models.DjangoStorage.user.create_user(username='username', password='password') @@ -129,7 +129,7 @@ class GetProviderUserStatesTestCase(TestCase): states = pipeline.get_provider_user_states(self.user) - self.assertEqual([], [x for x in social_models.DjangoStorage.user.objects.all()]) + self.assertEqual([], [x for x in social_models.DjangoStorage.user.objects.all()]) # lint-amnesty, pylint: disable=unnecessary-comprehension self.assertEqual(2, len(states)) google_state = [state for state in states if state.provider.provider_id == google_provider.provider_id][0] @@ -217,7 +217,7 @@ class TestPipelineUtilityFunctions(TestCase): Test some of the isolated utility functions in the pipeline """ def setUp(self): - super(TestPipelineUtilityFunctions, self).setUp() + super(TestPipelineUtilityFunctions, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = social_models.DjangoStorage.user.create_user(username='username', password='password') self.social_auth = social_models.UserSocialAuth.objects.create( user=self.user, @@ -307,7 +307,7 @@ class EnsureUserInformationTestCase(TestCase): """Tests ensuring that we have the necessary user information to proceed with the pipeline.""" def setUp(self): - super(EnsureUserInformationTestCase, self).setUp() + super(EnsureUserInformationTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = social_models.DjangoStorage.user.create_user( username='username', password='password', @@ -325,12 +325,12 @@ class EnsureUserInformationTestCase(TestCase): based on the provider's setting for send_to_registration_first. """ - provider = mock.MagicMock( + provider = mock.MagicMock( # lint-amnesty, pylint: disable=redefined-outer-name send_to_registration_first=send_to_registration_first, skip_email_verification=False ) - with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: + with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: # lint-amnesty, pylint: disable=line-too-long get_from_pipeline.return_value = provider with mock.patch('social_core.pipeline.partial.partial_prepare') as partial_prepare: partial_prepare.return_value = mock.MagicMock(token='') @@ -363,7 +363,7 @@ class EnsureUserInformationTestCase(TestCase): send_to_registration_first=True, skip_email_verification=False ) - with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: + with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: # lint-amnesty, pylint: disable=line-too-long get_from_pipeline.return_value = saml_provider with mock.patch( 'common.djangoapps.third_party_auth.pipeline.provider.Registry.get_enabled_by_backend_name' @@ -387,7 +387,7 @@ class UserDetailsForceSyncTestCase(TestCase): """Tests to ensure learner profile data is properly synced if the provider requires it.""" def setUp(self): - super(UserDetailsForceSyncTestCase, self).setUp() + super(UserDetailsForceSyncTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.old_email = self.user.email self.old_username = self.user.username @@ -404,7 +404,7 @@ class UserDetailsForceSyncTestCase(TestCase): self.strategy = mock.MagicMock() self.strategy.storage.user.changed.side_effect = lambda user: user.save() - get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') + get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') # lint-amnesty, pylint: disable=line-too-long self.get_from_pipeline = get_from_pipeline.start() self.get_from_pipeline.return_value = mock.MagicMock(sync_learner_profile_data=True) self.addCleanup(get_from_pipeline.stop) @@ -491,7 +491,7 @@ class SetIDVerificationStatusTestCase(TestCase): """Tests to ensure SSO ID Verification for the user is set if the provider requires it.""" def setUp(self): - super(SetIDVerificationStatusTestCase, self).setUp() + super(SetIDVerificationStatusTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.user = UserFactory.create() self.provider_class_name = 'common.djangoapps.third_party_auth.models.SAMLProviderConfig' self.provider_slug = 'default' @@ -501,7 +501,7 @@ class SetIDVerificationStatusTestCase(TestCase): self.strategy = mock.MagicMock() self.strategy.storage.user.changed.side_effect = lambda user: user.save() - get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') + get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') # lint-amnesty, pylint: disable=line-too-long self.get_from_pipeline = get_from_pipeline.start() self.get_from_pipeline.return_value = mock.MagicMock( enable_sso_id_verification=True, @@ -565,7 +565,7 @@ class SetIDVerificationStatusTestCase(TestCase): identity_provider_slug=self.provider_slug, ) - with mock.patch('common.djangoapps.third_party_auth.pipeline.earliest_allowed_verification_date') as earliest_date: + with mock.patch('common.djangoapps.third_party_auth.pipeline.earliest_allowed_verification_date') as earliest_date: # lint-amnesty, pylint: disable=line-too-long earliest_date.return_value = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=1) # Begin the pipeline. pipeline.set_id_verification_status( diff --git a/common/djangoapps/third_party_auth/tests/test_provider.py b/common/djangoapps/third_party_auth/tests/test_provider.py index 766b1e6736..68c24a86b8 100644 --- a/common/djangoapps/third_party_auth/tests/test_provider.py +++ b/common/djangoapps/third_party_auth/tests/test_provider.py @@ -2,7 +2,7 @@ import re -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from django.contrib.sites.models import Site from django.db import connections, DEFAULT_DB_ALIAS @@ -178,7 +178,7 @@ class RegistryTest(testutil.TestCase): which doesn't match any of the possible backend_names. """ google_provider = self.configure_google_provider(enabled=True, slug='custom_slug') - self.assertIn(google_provider, provider.Registry._enabled_providers()) + self.assertIn(google_provider, provider.Registry._enabled_providers()) # lint-amnesty, pylint: disable=protected-access self.assertIn(google_provider, provider.Registry.get_enabled_by_backend_name('google-oauth2')) def test_oath2_different_slug_from_backend_name(self): diff --git a/common/djangoapps/third_party_auth/tests/test_settings.py b/common/djangoapps/third_party_auth/tests/test_settings.py index 29a02b6aea..c817707680 100644 --- a/common/djangoapps/third_party_auth/tests/test_settings.py +++ b/common/djangoapps/third_party_auth/tests/test_settings.py @@ -1,7 +1,7 @@ """Unit tests for settings.py.""" -import unittest +import unittest # lint-amnesty, pylint: disable=unused-import from mock import patch from common.djangoapps.third_party_auth import provider, settings @@ -32,7 +32,7 @@ class SettingsUnitTest(testutil.TestCase): # pylint: disable=no-member def setUp(self): - super(SettingsUnitTest, self).setUp() + super(SettingsUnitTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.settings = testutil.FakeDjangoSettings(_SETTINGS_MAP) def test_apply_settings_adds_exception_middleware(self): diff --git a/common/djangoapps/third_party_auth/tests/test_views.py b/common/djangoapps/third_party_auth/tests/test_views.py index 642d24d57d..6f80d6117e 100644 --- a/common/djangoapps/third_party_auth/tests/test_views.py +++ b/common/djangoapps/third_party_auth/tests/test_views.py @@ -164,7 +164,7 @@ class IdPRedirectViewTest(SAMLTestCase): Test IdPRedirectView. """ def setUp(self): - super(IdPRedirectViewTest, self).setUp() + super(IdPRedirectViewTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.enable_saml() self.configure_saml_provider( diff --git a/common/djangoapps/third_party_auth/tests/testutil.py b/common/djangoapps/third_party_auth/tests/testutil.py index 4448c2d350..523ab53af4 100644 --- a/common/djangoapps/third_party_auth/tests/testutil.py +++ b/common/djangoapps/third_party_auth/tests/testutil.py @@ -12,7 +12,7 @@ import django.test import mock import six 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.contrib.sites.models import Site from mako.template import Template from oauth2_provider.models import Application @@ -64,11 +64,11 @@ class ThirdPartyAuthTestMixin(object): patch.start() self.addCleanup(patch.stop) - super(ThirdPartyAuthTestMixin, self).setUp(*args, **kwargs) + super(ThirdPartyAuthTestMixin, self).setUp(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def tearDown(self): config_cache.clear() - super(ThirdPartyAuthTestMixin, self).tearDown() + super(ThirdPartyAuthTestMixin, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments def enable_saml(self, **kwargs): """ Enable SAML support (via SAMLConfiguration, not for any particular provider) """ @@ -186,7 +186,7 @@ class TestCase(ThirdPartyAuthTestMixin, CacheIsolationMixin, django.test.TestCas """Base class for auth test cases.""" def setUp(self): # pylint: disable=arguments-differ - super(TestCase, self).setUp() + super(TestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Explicitly set a server name that is compatible with all our providers: # (The SAML lib we use doesn't like the default 'testserver' as a domain) self.hostname = 'example.none' @@ -215,7 +215,7 @@ class SAMLTestCase(TestCase): if 'public_key' not in kwargs: kwargs['public_key'] = self._get_public_key() kwargs.setdefault('entity_id', "https://saml.example.none") - super(SAMLTestCase, self).enable_saml(**kwargs) + super(SAMLTestCase, self).enable_saml(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments @contextmanager diff --git a/common/djangoapps/third_party_auth/tests/utils.py b/common/djangoapps/third_party_auth/tests/utils.py index cfdd989911..c0f4232d3e 100644 --- a/common/djangoapps/third_party_auth/tests/utils.py +++ b/common/djangoapps/third_party_auth/tests/utils.py @@ -33,8 +33,8 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin): CREATE_USER = True - def setUp(self): - super(ThirdPartyOAuthTestMixin, self).setUp() + def setUp(self): # lint-amnesty, pylint: disable=arguments-differ + super(ThirdPartyOAuthTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments if self.CREATE_USER: self.user = UserFactory() UserSocialAuth.objects.create(user=self.user, provider=self.BACKEND, uid=self.social_uid) @@ -45,7 +45,7 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin): self.configure_facebook_provider(enabled=True, visible=True) def tearDown(self): - super(ThirdPartyOAuthTestMixin, self).tearDown() + super(ThirdPartyOAuthTestMixin, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments Partial.objects.all().delete() def _create_client(self): diff --git a/common/djangoapps/third_party_auth/utils.py b/common/djangoapps/third_party_auth/utils.py index 8f2948623f..da0d55af12 100644 --- a/common/djangoapps/third_party_auth/utils.py +++ b/common/djangoapps/third_party_auth/utils.py @@ -3,7 +3,7 @@ Utility functions for third_party_auth """ from uuid import UUID -from django.contrib.auth.models import User +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user from enterprise.models import EnterpriseCustomerUser, EnterpriseCustomerIdentityProvider from . import provider @@ -49,7 +49,7 @@ def get_user_from_email(details): return None -def convert_saml_slug_provider_id(provider): +def convert_saml_slug_provider_id(provider): # lint-amnesty, pylint: disable=redefined-outer-name """ Provider id is stored with the backend type prefixed to it (ie "saml-") Slug is stored without this prefix. diff --git a/common/djangoapps/third_party_auth/views.py b/common/djangoapps/third_party_auth/views.py index c1b52b0305..5909f16f94 100644 --- a/common/djangoapps/third_party_auth/views.py +++ b/common/djangoapps/third_party_auth/views.py @@ -125,7 +125,7 @@ class IdPRedirectView(View): GET auth/idp_redirect/saml-default """ - def get(self, request, *args, **kwargs): + def get(self, request, *args, **kwargs): # lint-amnesty, pylint: disable=unused-argument """ Return either a redirect to the login page of an identity provider that corresponds to the provider_slug keyword argument or a 404 if the