From eb0f52d1100446c6593a2169906111824f3e3cc7 Mon Sep 17 00:00:00 2001 From: Bill Tucker Date: Fri, 10 May 2019 10:14:41 -0600 Subject: [PATCH] INCR-211: run python-modernize and isort (#20432) * INCR-211: run python-modernize and isort to support python2 --> python3 transition * INCR-211: fix pylint errors. Removed unused module import request and error. Used import as to avoid too deep a function call. Altering imports and using suppression of pylint's import error. * INCR-211: ignore pylint's import error from six module. * INCR-211: remove unused modules. Ignore pylint import error from six module. * INCR-211: ignore pylint's import error from six module. Group imports. * INCR-211: disable error of 'must be called with literal string' The specific context for this error means we can disable this. * INCR-211: change import to satisfy pylint by renaming import * INCR-211: fix imports so six.unichr works. --- .../djangoapps/user_authn/views/auto_auth.py | 9 ++++-- .../djangoapps/user_authn/views/deprecated.py | 17 +++++----- .../core/djangoapps/user_authn/views/login.py | 28 +++++++++-------- .../djangoapps/user_authn/views/login_form.py | 19 ++++++------ .../djangoapps/user_authn/views/logout.py | 8 +++-- .../djangoapps/user_authn/views/register.py | 31 +++++++------------ .../user_authn/views/tests/test_auto_auth.py | 14 ++++++--- .../user_authn/views/tests/test_login.py | 17 +++++----- .../tests/test_login_registration_forms.py | 19 +++++++----- .../user_authn/views/tests/test_logout.py | 14 ++++----- .../user_authn/views/tests/test_register.py | 18 +++++++---- .../user_authn/views/tests/test_views.py | 15 +++++---- 12 files changed, 114 insertions(+), 95 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/views/auto_auth.py b/openedx/core/djangoapps/user_authn/views/auto_auth.py index 9bd095f9ef..c7ab01dbb1 100644 --- a/openedx/core/djangoapps/user_authn/views/auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/auto_auth.py @@ -1,4 +1,6 @@ """ Views related to auto auth. """ +from __future__ import absolute_import + import datetime import uuid @@ -6,22 +8,24 @@ from django.conf import settings from django.contrib.auth import login as django_login from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied -from django.urls import NoReverseMatch, reverse from django.core.validators import ValidationError from django.http import HttpResponseForbidden from django.shortcuts import redirect from django.template.context_processors import csrf +from django.urls import NoReverseMatch, reverse from django.utils.translation import ugettext as _ +from opaque_keys.edx.locator import CourseLocator from lms.djangoapps.verify_student.models import ManualVerification -from opaque_keys.edx.locator import CourseLocator from openedx.core.djangoapps.django_comment_common.models import assign_role from openedx.core.djangoapps.user_api.accounts.utils import generate_password from openedx.features.course_experience import course_home_url_name from student.forms import AccountCreationForm from student.helpers import ( AccountValidationError, + authenticate_new_user, create_or_set_user_attribute_created_on_site, + do_create_account ) from student.models import ( CourseAccessRole, @@ -31,7 +35,6 @@ from student.models import ( anonymous_id_for_user, create_comments_service_user ) -from student.helpers import authenticate_new_user, do_create_account from util.json_request import JsonResponse diff --git a/openedx/core/djangoapps/user_authn/views/deprecated.py b/openedx/core/djangoapps/user_authn/views/deprecated.py index 19cf9147ae..af4f0160a1 100644 --- a/openedx/core/djangoapps/user_authn/views/deprecated.py +++ b/openedx/core/djangoapps/user_authn/views/deprecated.py @@ -1,4 +1,6 @@ """ User Authn code for deprecated views. """ +from __future__ import absolute_import + import warnings from django.conf import settings @@ -9,20 +11,15 @@ from django.http import HttpResponseForbidden from django.shortcuts import redirect from django.utils.translation import ugettext as _ from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie -from six import text_type, iteritems +from six import iteritems, text_type +import third_party_auth from edxmako.shortcuts import render_to_response - -from openedx.core.djangoapps.user_authn.views.register import create_account_with_params -from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, SYSTEM_MAINTENANCE_MSG, waffle -from student.helpers import ( - auth_pipeline_urls, - get_next_url_for_login_page -) -from student.helpers import AccountValidationError -import third_party_auth +from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies +from openedx.core.djangoapps.user_authn.views.register import create_account_with_params +from student.helpers import AccountValidationError, auth_pipeline_urls, get_next_url_for_login_page from third_party_auth import pipeline, provider from util.json_request import JsonResponse diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 40ea671049..8cc5f89c5b 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -4,32 +4,34 @@ Views for login / logout and associated functionality Much of this file was broken out from views.py, previous history can be found there. """ +from __future__ import absolute_import + import logging from django.conf import settings -from django.contrib.auth import authenticate, login as django_login +from django.contrib.auth import authenticate +from django.contrib.auth import login as django_login from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User -from django.urls import reverse from django.http import HttpResponse from django.utils.translation import ugettext as _ from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie from django.views.decorators.http import require_http_methods from ratelimitbackend.exceptions import RateLimitException -from edxmako.shortcuts import render_to_response -from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies, refresh_jwt_cookies -from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError -from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers -from openedx.core.djangoapps.util.user_messages import PageLevelMessages -from openedx.core.djangolib.markup import HTML, Text -from student.models import LoginFailures -from student.views import send_reactivation_email_for_user -from student.forms import send_password_reset_email_for_user -from track import segment import third_party_auth from third_party_auth import pipeline, provider +from edxmako.shortcuts import render_to_response +from openedx.core.djangoapps.password_policy import compliance as password_policy_compliance +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_authn.cookies import refresh_jwt_cookies, set_logged_in_cookies +from openedx.core.djangoapps.user_authn.exceptions import AuthFailedError +from openedx.core.djangoapps.util.user_messages import PageLevelMessages +from openedx.core.djangolib.markup import HTML, Text +from student.forms import send_password_reset_email_for_user +from student.models import LoginFailures +from student.views import send_reactivation_email_for_user +from track import segment from util.json_request import JsonResponse from util.password_policy_validators import normalize_password diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index 04d2c3c1dd..3920df1e54 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -1,9 +1,12 @@ """ Login related views """ +from __future__ import absolute_import + import json import logging -import urlparse +import six +import six.moves.urllib.parse # pylint: disable=import-error from django.conf import settings from django.contrib import messages from django.shortcuts import redirect @@ -12,29 +15,27 @@ from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_http_methods from edxmako.shortcuts import render_to_response -from openedx.core.djangoapps.user_authn.views.deprecated import ( - register_user as old_register_view, signin_user as old_login_view -) from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming.helpers import is_request_in_themed_site from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_feature_enabled from openedx.core.djangoapps.user_api.api import ( RegistrationFormFactory, get_login_session_form, - get_password_reset_form, + get_password_reset_form ) from openedx.core.djangoapps.user_authn.cookies import are_logged_in_cookies_set +from openedx.core.djangoapps.user_authn.views.deprecated import register_user as old_register_view +from openedx.core.djangoapps.user_authn.views.deprecated import signin_user as old_login_view from openedx.features.enterprise_support.api import enterprise_customer_for_request from openedx.features.enterprise_support.utils import ( handle_enterprise_cookies_for_logistration, - update_logistration_context_for_enterprise, + update_logistration_context_for_enterprise ) from student.helpers import get_next_url_for_login_page import third_party_auth from third_party_auth import pipeline from third_party_auth.decorators import xframe_allow_whitelisted - log = logging.getLogger(__name__) @@ -69,7 +70,7 @@ def login_and_registration_form(request, initial_mode="login"): third_party_auth_hint = None if '?' in redirect_to: try: - next_args = urlparse.parse_qs(urlparse.urlparse(redirect_to).query) + next_args = six.moves.urllib.parse.parse_qs(six.moves.urllib.parse.urlparse(redirect_to).query) provider_id = next_args['tpa_hint'][0] tpa_hint_provider = third_party_auth.provider.Registry.get(provider_id=provider_id) if tpa_hint_provider: @@ -239,7 +240,7 @@ def _third_party_auth_context(request, redirect_to, tpa_hint=None): for msg in messages.get_messages(request): if msg.extra_tags.split()[0] == "social-auth": # msg may or may not be translated. Try translating [again] in case we are able to: - context['errorMessage'] = _(unicode(msg)) + context["errorMessage"] = _(six.text_type(msg)) # pylint: disable=E7610 break return context diff --git a/openedx/core/djangoapps/user_authn/views/logout.py b/openedx/core/djangoapps/user_authn/views/logout.py index bdd49ea34b..e9276a51e9 100644 --- a/openedx/core/djangoapps/user_authn/views/logout.py +++ b/openedx/core/djangoapps/user_authn/views/logout.py @@ -1,14 +1,16 @@ """ Views related to logout. """ -import urllib -from urlparse import parse_qs, urlsplit, urlunsplit +from __future__ import absolute_import import edx_oauth2_provider +from six.moves.urllib.parse import parse_qs, urlsplit, urlunsplit # pylint: disable=import-error +import six.moves.urllib.parse as parse # pylint: disable=import-error from django.conf import settings from django.contrib.auth import logout from django.shortcuts import redirect from django.utils.http import urlencode from django.views.generic import TemplateView from provider.oauth2.models import Client + from openedx.core.djangoapps.user_authn.cookies import delete_logged_in_cookies from openedx.core.djangoapps.user_authn.utils import is_safe_login_or_logout_redirect @@ -53,7 +55,7 @@ class LogoutView(TemplateView): # >> /courses/course-v1:ARTS+D1+2018_T/course/ # to handle this scenario we need to encode our URL using quote_plus and then unquote it again. if target_url: - target_url = urllib.unquote(urllib.quote_plus(target_url)) + target_url = parse.unquote(parse.quote_plus(target_url)) if target_url and is_safe_login_or_logout_redirect(self.request, target_url): return target_url diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 43ee1acf82..215426f64a 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -2,6 +2,8 @@ Registration related views. """ +from __future__ import absolute_import + import datetime import json import logging @@ -9,47 +11,36 @@ import logging from django.conf import settings from django.contrib.auth import login as django_login from django.contrib.auth.models import User -from django.urls import reverse from django.core.validators import ValidationError, validate_email from django.db import transaction from django.dispatch import Signal +from django.urls import reverse from django.utils.translation import get_language from django.utils.translation import ugettext as _ - -# Note that this lives in LMS, so this dependency should be refactored. -# TODO Have the discussions code subscribe to the REGISTER_USER signal instead. -from lms.djangoapps.discussion.notification_prefs.views import enable_notifications from pytz import UTC from requests import HTTPError from six import text_type from social_core.exceptions import AuthAlreadyAssociated, AuthException from social_django import utils as social_utils +import third_party_auth +# Note that this lives in LMS, so this dependency should be refactored. +# TODO Have the discussions code subscribe to the REGISTER_USER signal instead. +from lms.djangoapps.discussion.notification_prefs.views import enable_notifications from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api import accounts as accounts_settings from openedx.core.djangoapps.user_api.accounts.utils import generate_password from openedx.core.djangoapps.user_api.preferences import api as preferences_api - from student.forms import AccountCreationForm, get_registration_extension_form -from student.helpers import ( - authenticate_new_user, - create_or_set_user_attribute_created_on_site, - do_create_account, -) -from student.models import ( - RegistrationCookieConfiguration, - UserAttribute, - create_comments_service_user, -) +from student.helpers import authenticate_new_user, create_or_set_user_attribute_created_on_site, do_create_account +from student.models import RegistrationCookieConfiguration, UserAttribute, create_comments_service_user from student.views import compose_and_send_activation_email -from track import segment -import third_party_auth from third_party_auth import pipeline, provider from third_party_auth.saml import SAP_SUCCESSFACTORS_SAML_KEY +from track import segment from util.db import outer_atomic - log = logging.getLogger("edx.student") AUDIT_LOG = logging.getLogger("audit") @@ -105,7 +96,7 @@ def create_account_with_params(request, params): """ # Copy params so we can modify it; we can't just do dict(params) because if # params is request.POST, that results in a dict containing lists of values - params = dict(params.items()) + params = dict(list(params.items())) # allow to define custom set of required/optional/hidden fields via configuration extra_fields = configuration_helpers.get_value( diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py index fadf004b73..4abf01af06 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_auto_auth.py @@ -1,19 +1,25 @@ """ Tests for auto auth. """ +from __future__ import absolute_import + import json import ddt +import six from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase from django.test.client import Client -from mock import patch, Mock +from mock import Mock, patch from opaque_keys.edx.locator import CourseLocator from openedx.core.djangoapps.django_comment_common.models import ( - Role, FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_STUDENT + FORUM_ROLE_ADMINISTRATOR, + FORUM_ROLE_MODERATOR, + FORUM_ROLE_STUDENT, + Role ) from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles -from student.models import anonymous_id_for_user, CourseAccessRole, CourseEnrollment, UserProfile +from student.models import CourseAccessRole, CourseEnrollment, UserProfile, anonymous_id_for_user from util.testing import UrlResetMixin @@ -207,7 +213,7 @@ class AutoAuthEnabledTestCase(AutoAuthTestCase): if settings.ROOT_URLCONF == 'lms.urls': url_pattern = '/course/' else: - url_pattern = '/course/{}'.format(unicode(course_key)) + url_pattern = '/course/{}'.format(six.text_type(course_key)) self.assertTrue(response.url.endswith(url_pattern)) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index ff87762acc..00d6152f2d 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -2,11 +2,14 @@ """ Tests for student activation and login """ +from __future__ import absolute_import + import json import unicodedata -import unittest import ddt +import six +from six.moves import range from django.conf import settings from django.contrib.auth.models import User from django.core import mail @@ -74,7 +77,7 @@ class LoginTest(CacheIsolationTestCase): self._assert_not_in_audit_log(mock_audit_log, 'info', [u'test@edx.org']) def test_login_success_unicode_email(self): - unicode_email = u'test' + unichr(40960) + u'@edx.org' + unicode_email = u'test' + six.unichr(40960) + u'@edx.org' self.user.email = unicode_email self.user.save() @@ -180,7 +183,7 @@ class LoginTest(CacheIsolationTestCase): self._assert_not_in_audit_log(mock_audit_log, 'warning', [u'test']) def test_login_unicode_email(self): - unicode_email = u'test@edx.org' + unichr(40960) + unicode_email = u'test@edx.org' + six.unichr(40960) response, mock_audit_log = self._login_response( unicode_email, 'test_password', @@ -189,7 +192,7 @@ class LoginTest(CacheIsolationTestCase): self._assert_audit_log(mock_audit_log, 'warning', [u'Login failed', unicode_email]) def test_login_unicode_password(self): - unicode_password = u'test_password' + unichr(1972) + unicode_password = u'test_password' + six.unichr(1972) response, mock_audit_log = self._login_response( 'test@edx.org', unicode_password, @@ -271,7 +274,7 @@ class LoginTest(CacheIsolationTestCase): def test_login_ratelimited_success(self): # Try (and fail) logging in with fewer attempts than the limit of 30 # and verify that you can still successfully log in afterwards. - for i in xrange(20): + for i in range(20): password = u'test_password{0}'.format(i) response, _audit_log = self._login_response('test@edx.org', password) self._assert_response(response, success=False) @@ -282,7 +285,7 @@ class LoginTest(CacheIsolationTestCase): def test_login_ratelimited(self): # try logging in 30 times, the default limit in the number of failed # login attempts in one 5 minute period before the rate gets limited - for i in xrange(30): + for i in range(30): password = u'test_password{0}'.format(i) self._login_response('test@edx.org', password) # check to see if this response indicates that this was ratelimited @@ -545,7 +548,7 @@ class LoginTest(CacheIsolationTestCase): if value is not None: msg = (u"'%s' did not contain '%s'" % - (unicode(response_dict['value']), unicode(value))) + (six.text_type(response_dict['value']), six.text_type(value))) self.assertIn(value, response_dict['value'], msg) def _assert_audit_log(self, mock_audit_log, level, log_strings): diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login_registration_forms.py b/openedx/core/djangoapps/user_authn/views/tests/test_login_registration_forms.py index ba195a0182..4f2f1dee57 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login_registration_forms.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login_registration_forms.py @@ -1,8 +1,13 @@ """Tests for the login and registration form rendering. """ +from __future__ import absolute_import + import unittest -import urllib import ddt +import six +import six.moves.urllib.error # pylint: disable=import-error +import six.moves.urllib.parse # pylint: disable=import-error +import six.moves.urllib.request # pylint: disable=import-error from django.conf import settings from django.urls import reverse from mock import patch @@ -26,13 +31,13 @@ def _third_party_login_url(backend_name, auth_entry, redirect_url=None): return u"{url}?{params}".format( url=reverse("social:begin", kwargs={"backend": backend_name}), - params=urllib.urlencode(params) + params=six.moves.urllib.parse.urlencode(params) ) def _finish_auth_url(params): """ Construct the URL that follows login/registration if we are doing auto-enrollment """ - return u"{}?{}".format(reverse('finish_auth'), urllib.urlencode(params)) + return u"{}?{}".format(reverse('finish_auth'), six.moves.urllib.parse.urlencode(params)) @ddt.ddt @@ -55,7 +60,7 @@ class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTes super(LoginFormTest, self).setUp() self.url = reverse("signin_user") - self.course_id = unicode(self.course.id) + self.course_id = six.text_type(self.course.id) self.courseware_url = reverse("courseware", args=[self.course_id]) self.configure_google_provider(enabled=True, visible=True) self.configure_facebook_provider(enabled=True, visible=True) @@ -150,7 +155,7 @@ class LoginFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStoreTes # Verify that the login link preserves the querystring params login_link = u"{url}?{params}".format( url=reverse('signin_user'), - params=urllib.urlencode([('next', post_login_handler)]) + params=six.moves.urllib.parse.urlencode([('next', post_login_handler)]) ) self.assertContains(response, login_link) @@ -172,7 +177,7 @@ class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStore super(RegisterFormTest, self).setUp() self.url = reverse("register_user") - self.course_id = unicode(self.course.id) + self.course_id = six.text_type(self.course.id) self.configure_google_provider(enabled=True, visible=True) self.configure_facebook_provider(enabled=True, visible=True) @@ -226,6 +231,6 @@ class RegisterFormTest(ThirdPartyAuthTestMixin, UrlResetMixin, SharedModuleStore # Verify that the login link preserves the querystring params login_link = u"{url}?{params}".format( url=reverse('signin_user'), - params=urllib.urlencode([('next', post_login_handler)]) + params=six.moves.urllib.parse.urlencode([('next', post_login_handler)]) ) self.assertContains(response, login_link) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py index 0a0fecf693..5edd571a9c 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_logout.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_logout.py @@ -1,20 +1,20 @@ """ Tests for logout """ +from __future__ import absolute_import + import unittest -import urllib import ddt +import six.moves.urllib.parse as parse # pylint: disable=import-error from django.conf import settings from django.test import TestCase from django.test.utils import override_settings from django.urls import reverse -from mock import patch from edx_oauth2_provider.constants import AUTHORIZED_CLIENTS_SESSION_KEY -from edx_oauth2_provider.tests.factories import ( - ClientFactory, - TrustedClientFactory -) +from edx_oauth2_provider.tests.factories import ClientFactory, TrustedClientFactory +from mock import patch + from student.tests.factories import UserFactory @@ -81,7 +81,7 @@ class LogoutTests(TestCase): ) response = self.client.get(url, HTTP_HOST=host) expected = { - 'target': urllib.unquote(redirect_url), + 'target': parse.unquote(redirect_url), } self.assertDictContainsSubset(expected, response.context_data) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index cfc78fa353..751df621fc 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -1,33 +1,39 @@ # -*- coding: utf-8 -*- """Tests for account creation""" +from __future__ import absolute_import + import json +import unicodedata import unittest from datetime import datetime -import unicodedata import ddt import mock import pytz from django.conf import settings +from django.contrib.auth.hashers import make_password from django.contrib.auth.models import AnonymousUser, User -from django.urls import reverse from django.test import TestCase, TransactionTestCase from django.test.client import RequestFactory from django.test.utils import override_settings -from django.contrib.auth.hashers import make_password +from django.urls import reverse from lms.djangoapps.discussion.notification_prefs import NOTIFICATION_PREF_KEY from openedx.core.djangoapps.django_comment_common.models import ForumsConfig from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.user_api.accounts import ( - USERNAME_BAD_LENGTH_MSG, USERNAME_INVALID_CHARS_ASCII, USERNAME_INVALID_CHARS_UNICODE + USERNAME_BAD_LENGTH_MSG, + USERNAME_INVALID_CHARS_ASCII, + USERNAME_INVALID_CHARS_UNICODE ) from openedx.core.djangoapps.user_api.config.waffle import PREVENT_AUTH_USER_WRITES, waffle from openedx.core.djangoapps.user_api.preferences.api import get_user_preference from openedx.core.djangoapps.user_authn.views.register import ( - REGISTRATION_AFFILIATE_ID, REGISTRATION_UTM_CREATED_AT, REGISTRATION_UTM_PARAMETERS, - _skip_activation_email, + REGISTRATION_AFFILIATE_ID, + REGISTRATION_UTM_CREATED_AT, + REGISTRATION_UTM_PARAMETERS, + _skip_activation_email ) from student.models import UserAttribute from student.tests.factories import UserFactory diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_views.py b/openedx/core/djangoapps/user_authn/views/tests/test_views.py index cd4bc907ee..6340c47cc7 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_views.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_views.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- """ Tests for user authn views. """ -from http.cookies import SimpleCookie +from __future__ import absolute_import + import logging import re +from http.cookies import SimpleCookie from unittest import skipUnless -from urllib import urlencode import ddt import mock @@ -17,27 +18,29 @@ from django.contrib.messages.middleware import MessageMiddleware from django.contrib.sessions.middleware import SessionMiddleware from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile -from django.urls import reverse from django.test import TestCase from django.test.client import RequestFactory from django.test.utils import override_settings +from django.urls import reverse from django.utils.translation import ugettext as _ from edx_oauth2_provider.tests.factories import AccessTokenFactory, ClientFactory, RefreshTokenFactory from oauth2_provider.models import AccessToken as dot_access_token from oauth2_provider.models import RefreshToken as dot_refresh_token from provider.oauth2.models import AccessToken as dop_access_token from provider.oauth2.models import RefreshToken as dop_refresh_token +from six.moves import range +from six.moves.urllib.parse import urlencode # pylint: disable=import-error from testfixtures import LogCapture from waffle.models import Switch from course_modes.models import CourseMode -from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form from openedx.core.djangoapps.oauth_dispatch.tests import factories as dot_factories from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme_context from openedx.core.djangoapps.user_api.accounts.api import activate_account, create_account -from openedx.core.djangoapps.user_api.errors import UserAPIInternalError from openedx.core.djangoapps.user_api.accounts.utils import ENABLE_SECONDARY_EMAIL_FEATURE_SWITCH +from openedx.core.djangoapps.user_api.errors import UserAPIInternalError +from openedx.core.djangoapps.user_authn.views.login_form import login_and_registration_form from openedx.core.djangolib.js_utils import dump_js_escaped_json from openedx.core.djangolib.markup import HTML, Text from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms @@ -241,7 +244,7 @@ class UserAccountUpdateTest(CacheIsolationTestCase, UrlResetMixin): self.client.logout() # Make many consecutive bad requests in an attempt to trigger the rate limiter - for __ in xrange(self.INVALID_ATTEMPTS): + for __ in range(self.INVALID_ATTEMPTS): self._change_password(email=self.NEW_EMAIL) response = self._change_password(email=self.NEW_EMAIL)