PLAT-1915 Stop using deprecated BaseException.message
This commit is contained in:
@@ -4,6 +4,7 @@ Command to load course blocks.
|
||||
import logging
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from six import text_type
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
import openedx.core.djangoapps.content.block_structure.api as api
|
||||
@@ -136,7 +137,7 @@ class Command(BaseCommand):
|
||||
log.exception(
|
||||
u'BlockStructure: An error occurred while generating course blocks for %s: %s',
|
||||
unicode(course_key),
|
||||
ex.message,
|
||||
text_type(ex),
|
||||
)
|
||||
|
||||
def _generate_for_course(self, options, course_key):
|
||||
|
||||
@@ -13,6 +13,7 @@ from django.template import defaultfilters
|
||||
|
||||
from ccx_keys.locator import CCXLocator
|
||||
from model_utils.models import TimeStampedModel
|
||||
from six import text_type
|
||||
|
||||
from config_models.models import ConfigurationModel
|
||||
from lms.djangoapps import django_comment_client
|
||||
@@ -528,7 +529,7 @@ class CourseOverview(TimeStampedModel):
|
||||
log.exception(
|
||||
'An error occurred while generating course overview for %s: %s',
|
||||
unicode(course_key),
|
||||
ex.message,
|
||||
text_type(ex),
|
||||
)
|
||||
|
||||
log.info('Finished generating course overviews.')
|
||||
|
||||
@@ -51,6 +51,6 @@ class Command(BaseCommand):
|
||||
update_course_structure.apply(args=[text_type(course_key)])
|
||||
except Exception as ex:
|
||||
log.exception('An error occurred while generating course structure for %s: %s',
|
||||
text_type(course_key), ex.message)
|
||||
text_type(course_key), text_type(ex))
|
||||
|
||||
log.info('Finished generating course structures.')
|
||||
|
||||
@@ -6,6 +6,8 @@ import logging
|
||||
|
||||
from celery.task import task
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from six import text_type
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
|
||||
@@ -78,7 +80,7 @@ def update_course_structure(course_key):
|
||||
try:
|
||||
structure = _generate_course_structure(course_key)
|
||||
except Exception as ex:
|
||||
log.exception('An error occurred while generating course structure: %s', ex.message)
|
||||
log.exception('An error occurred while generating course structure: %s', text_type(ex))
|
||||
raise
|
||||
|
||||
structure_json = json.dumps(structure['structure'])
|
||||
|
||||
@@ -12,6 +12,7 @@ except ImportError:
|
||||
from django.http import (
|
||||
HttpResponse, HttpResponseNotModified, HttpResponseForbidden,
|
||||
HttpResponseBadRequest, HttpResponseNotFound, HttpResponsePermanentRedirect)
|
||||
from six import text_type
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
from xmodule.assetstore.assetmgr import AssetManager
|
||||
@@ -132,18 +133,18 @@ class StaticContentServer(object):
|
||||
except ValueError as exception:
|
||||
# If the header field is syntactically invalid it should be ignored.
|
||||
log.exception(
|
||||
u"%s in Range header: %s for content: %s", exception.message, header_value, unicode(loc)
|
||||
u"%s in Range header: %s for content: %s", text_type(exception), header_value, unicode(loc)
|
||||
)
|
||||
else:
|
||||
if unit != 'bytes':
|
||||
# Only accept ranges in bytes
|
||||
log.warning(u"Unknown unit in Range header: %s for content: %s", header_value, unicode(loc))
|
||||
log.warning(u"Unknown unit in Range header: %s for content: %s", header_value, text_type(loc))
|
||||
elif len(ranges) > 1:
|
||||
# According to Http/1.1 spec content for multiple ranges should be sent as a multipart message.
|
||||
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
|
||||
# But we send back the full content.
|
||||
log.warning(
|
||||
u"More than 1 ranges in Range header: %s for content: %s", header_value, unicode(loc)
|
||||
u"More than 1 ranges in Range header: %s for content: %s", header_value, text_type(loc)
|
||||
)
|
||||
else:
|
||||
first, last = ranges[0]
|
||||
@@ -161,7 +162,8 @@ class StaticContentServer(object):
|
||||
newrelic.agent.add_custom_parameter('contentserver.ranged', True)
|
||||
else:
|
||||
log.warning(
|
||||
u"Cannot satisfy ranges in Range header: %s for content: %s", header_value, unicode(loc)
|
||||
u"Cannot satisfy ranges in Range header: %s for content: %s",
|
||||
header_value, text_type(loc)
|
||||
)
|
||||
return HttpResponse(status=416) # Requested Range Not Satisfiable
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ from django.db import IntegrityError
|
||||
from django.http import Http404
|
||||
from django.test import TestCase
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
from six import text_type
|
||||
|
||||
from student.models import CourseEnrollment
|
||||
from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -720,7 +722,7 @@ class TestCohorts(ModuleStoreTestCase):
|
||||
with self.assertRaises(ValueError) as value_error:
|
||||
cohorts.set_course_cohorted(course.id, 'not a boolean')
|
||||
|
||||
self.assertEqual("Cohorted must be a boolean", value_error.exception.message)
|
||||
self.assertEqual("Cohorted must be a boolean", text_type(value_error.exception))
|
||||
|
||||
|
||||
@attr(shard=2)
|
||||
|
||||
@@ -18,6 +18,7 @@ from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.response import Response
|
||||
from rest_framework_oauth.authentication import OAuth2Authentication
|
||||
from six import text_type
|
||||
|
||||
from openedx.core.djangoapps.credit.api import create_credit_request
|
||||
from openedx.core.djangoapps.credit.exceptions import (
|
||||
@@ -101,7 +102,7 @@ class CreditProviderRequestCreateView(views.APIView):
|
||||
credit_request = create_credit_request(course_key, provider.provider_id, username)
|
||||
return Response(credit_request)
|
||||
except CreditApiBadRequest as ex:
|
||||
raise InvalidCreditRequest(ex.message)
|
||||
raise InvalidCreditRequest(text_type(ex))
|
||||
|
||||
|
||||
class CreditProviderCallbackView(views.APIView):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Exceptions related to the handling of profile images.
|
||||
"""
|
||||
from six import text_type
|
||||
|
||||
|
||||
class ImageValidationError(Exception):
|
||||
@@ -12,4 +13,4 @@ class ImageValidationError(Exception):
|
||||
"""
|
||||
Translate the developer-facing exception message for API clients.
|
||||
"""
|
||||
return self.message
|
||||
return text_type(self)
|
||||
|
||||
@@ -14,6 +14,7 @@ import mock
|
||||
from nose.plugins.attrib import attr
|
||||
import piexif
|
||||
from PIL import Image
|
||||
from six import text_type
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from ..exceptions import ImageValidationError
|
||||
@@ -48,7 +49,7 @@ class TestValidateUploadedImage(TestCase):
|
||||
if expected_failure_message is not None:
|
||||
with self.assertRaises(ImageValidationError) as ctx:
|
||||
validate_uploaded_image(uploaded_file)
|
||||
self.assertEqual(ctx.exception.message, expected_failure_message)
|
||||
self.assertEqual(text_type(ctx.exception), expected_failure_message)
|
||||
else:
|
||||
validate_uploaded_image(uploaded_file)
|
||||
self.assertEqual(uploaded_file.tell(), 0)
|
||||
@@ -107,7 +108,7 @@ class TestValidateUploadedImage(TestCase):
|
||||
)
|
||||
with self.assertRaises(ImageValidationError) as ctx:
|
||||
validate_uploaded_image(uploaded_file)
|
||||
self.assertEqual(ctx.exception.message, file_upload_bad_ext)
|
||||
self.assertEqual(text_type(ctx.exception), file_upload_bad_ext)
|
||||
|
||||
def test_content_type(self):
|
||||
"""
|
||||
@@ -121,7 +122,7 @@ class TestValidateUploadedImage(TestCase):
|
||||
with make_uploaded_file(extension=".jpeg", content_type="image/gif") as uploaded_file:
|
||||
with self.assertRaises(ImageValidationError) as ctx:
|
||||
validate_uploaded_image(uploaded_file)
|
||||
self.assertEqual(ctx.exception.message, file_upload_bad_mimetype)
|
||||
self.assertEqual(text_type(ctx.exception), file_upload_bad_mimetype)
|
||||
|
||||
|
||||
@attr(shard=2)
|
||||
|
||||
@@ -12,6 +12,7 @@ from rest_framework import permissions, status
|
||||
from rest_framework.parsers import FormParser, MultiPartParser
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from six import text_type
|
||||
|
||||
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_names, set_has_profile_image
|
||||
from openedx.core.djangoapps.user_api.errors import UserNotFound
|
||||
@@ -145,7 +146,7 @@ class ProfileImageView(DeveloperErrorViewMixin, APIView):
|
||||
validate_uploaded_image(uploaded_file)
|
||||
except ImageValidationError as error:
|
||||
return Response(
|
||||
{"developer_message": error.message, "user_message": error.user_message},
|
||||
{"developer_message": text_type(error), "user_message": error.user_message},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.core import signing
|
||||
from django.http import HttpResponse
|
||||
from django.utils.crypto import get_random_string
|
||||
from six import text_type
|
||||
|
||||
from openedx.core.lib.mobile_utils import is_request_from_mobile_app
|
||||
|
||||
@@ -186,7 +187,7 @@ class SafeCookieData(object):
|
||||
log.error(
|
||||
"SafeCookieData signature error for cookie data {0!r}: {1}".format( # pylint: disable=logging-format-interpolation
|
||||
unicode(self),
|
||||
sig_error.message,
|
||||
text_type(sig_error),
|
||||
)
|
||||
)
|
||||
return False
|
||||
|
||||
@@ -13,6 +13,7 @@ from django.core.validators import validate_email, ValidationError
|
||||
from django.http import HttpResponseForbidden
|
||||
from openedx.core.djangoapps.user_api.preferences.api import update_user_preferences
|
||||
from openedx.core.djangoapps.user_api.errors import PreferenceValidationError, AccountValidationError
|
||||
from six import text_type
|
||||
|
||||
from student.models import User, UserProfile, Registration
|
||||
from student import forms as student_forms
|
||||
@@ -168,8 +169,8 @@ def update_account_settings(requesting_user, update, username=None):
|
||||
student_views.validate_new_email(existing_user, new_email)
|
||||
except ValueError as err:
|
||||
field_errors["email"] = {
|
||||
"developer_message": u"Error thrown from validate_new_email: '{}'".format(err.message),
|
||||
"user_message": err.message
|
||||
"developer_message": u"Error thrown from validate_new_email: '{}'".format(text_type(err)),
|
||||
"user_message": text_type(err)
|
||||
}
|
||||
|
||||
# If the user asked to change full name, validate it
|
||||
@@ -245,7 +246,7 @@ def update_account_settings(requesting_user, update, username=None):
|
||||
raise err
|
||||
except Exception as err:
|
||||
raise errors.AccountUpdateError(
|
||||
u"Error thrown when saving account updates: '{}'".format(err.message)
|
||||
u"Error thrown when saving account updates: '{}'".format(text_type(err))
|
||||
)
|
||||
|
||||
# And try to send the email change request if necessary.
|
||||
@@ -256,8 +257,8 @@ def update_account_settings(requesting_user, update, username=None):
|
||||
student_views.do_email_change_request(existing_user, new_email)
|
||||
except ValueError as err:
|
||||
raise errors.AccountUpdateError(
|
||||
u"Error thrown from do_email_change_request: '{}'".format(err.message),
|
||||
user_message=err.message
|
||||
u"Error thrown from do_email_change_request: '{}'".format(text_type(err)),
|
||||
user_message=text_type(err)
|
||||
)
|
||||
|
||||
|
||||
@@ -552,7 +553,7 @@ def _validate(validation_func, err, *args):
|
||||
try:
|
||||
validation_func(*args)
|
||||
except err as validation_err:
|
||||
return validation_err.message
|
||||
return text_type(validation_err)
|
||||
return ''
|
||||
|
||||
|
||||
@@ -582,8 +583,10 @@ def _validate_username(username):
|
||||
# `validate_username` provides a proper localized message, however the API needs only the English
|
||||
# message by convention.
|
||||
student_forms.validate_username(username)
|
||||
except (UnicodeError, errors.AccountDataBadType, errors.AccountDataBadLength, ValidationError) as username_err:
|
||||
raise errors.AccountUsernameInvalid(username_err.message)
|
||||
except (UnicodeError, errors.AccountDataBadType, errors.AccountDataBadLength) as username_err:
|
||||
raise errors.AccountUsernameInvalid(text_type(username_err))
|
||||
except ValidationError as validation_err:
|
||||
raise errors.AccountUsernameInvalid(validation_err.message)
|
||||
|
||||
|
||||
def _validate_email(email):
|
||||
@@ -605,8 +608,10 @@ def _validate_email(email):
|
||||
_validate_length(email, accounts.EMAIL_MIN_LENGTH, accounts.EMAIL_MAX_LENGTH, accounts.EMAIL_BAD_LENGTH_MSG)
|
||||
validate_email.message = accounts.EMAIL_INVALID_MSG.format(email=email)
|
||||
validate_email(email)
|
||||
except (UnicodeError, errors.AccountDataBadType, errors.AccountDataBadLength, ValidationError) as invalid_email_err:
|
||||
raise errors.AccountEmailInvalid(invalid_email_err.message)
|
||||
except (UnicodeError, errors.AccountDataBadType, errors.AccountDataBadLength) as invalid_email_err:
|
||||
raise errors.AccountEmailInvalid(text_type(invalid_email_err))
|
||||
except ValidationError as validation_err:
|
||||
raise errors.AccountEmailInvalid(validation_err.message)
|
||||
|
||||
|
||||
def _validate_confirm_email(confirm_email, email):
|
||||
@@ -650,7 +655,7 @@ def _validate_password(password, username=None):
|
||||
|
||||
_validate_password_works_with_username(password, username)
|
||||
except (errors.AccountDataBadType, errors.AccountDataBadLength) as invalid_password_err:
|
||||
raise errors.AccountPasswordInvalid(invalid_password_err.message)
|
||||
raise errors.AccountPasswordInvalid(text_type(invalid_password_err))
|
||||
|
||||
|
||||
def _validate_country(country):
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.urlresolvers import reverse
|
||||
from six import text_type
|
||||
|
||||
from lms.djangoapps.badges.utils import badges_enabled
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
@@ -313,8 +314,8 @@ class AccountLegacyProfileSerializer(serializers.HyperlinkedModelSerializer, Rea
|
||||
# If we have encountered any validation errors, return them to the user.
|
||||
raise errors.AccountValidationError({
|
||||
'social_links': {
|
||||
"developer_message": u"Error thrown from adding new social link: '{}'".format(err.message),
|
||||
"user_message": err.message
|
||||
"developer_message": u"Error thrown from adding new social link: '{}'".format(text_type(err)),
|
||||
"user_message": text_type(err)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ from django.utils.translation import ugettext_noop
|
||||
|
||||
from openedx.core.lib.time_zone_utils import get_display_time_zone
|
||||
from pytz import common_timezones, common_timezones_set, country_timezones
|
||||
from six import text_type
|
||||
|
||||
from student.models import User, UserProfile
|
||||
from ..errors import (
|
||||
UserAPIInternalError, UserAPIRequestError, UserNotFound, UserNotAuthorized,
|
||||
@@ -266,7 +268,7 @@ def update_email_opt_in(user, org, opt_in):
|
||||
if hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY:
|
||||
_track_update_email_opt_in(user.id, org, opt_in)
|
||||
except IntegrityError as err:
|
||||
log.warn(u"Could not update organization wide preference due to IntegrityError: {}".format(err.message))
|
||||
log.warning(u"Could not update organization wide preference due to IntegrityError: {}".format(text_type(err)))
|
||||
|
||||
|
||||
def _track_update_email_opt_in(user_id, organization, opt_in):
|
||||
|
||||
@@ -9,6 +9,8 @@ from django import forms
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import TestCase
|
||||
from nose.tools import raises
|
||||
from six import text_type
|
||||
|
||||
from ..helpers import (
|
||||
intercept_errors, shim_student_view,
|
||||
FormDescription, InvalidFieldError
|
||||
@@ -66,7 +68,7 @@ class InterceptErrorsTest(TestCase):
|
||||
try:
|
||||
intercepted_function(raise_error=FakeInputException)
|
||||
except FakeOutputException as ex:
|
||||
actual_message = re.sub(r'line \d+', 'line XXX', ex.message, flags=re.MULTILINE)
|
||||
actual_message = re.sub(r'line \d+', 'line XXX', text_type(ex), flags=re.MULTILINE)
|
||||
self.assertEqual(actual_message, expected_log_msg)
|
||||
|
||||
# Verify that the error logger is called
|
||||
|
||||
@@ -9,6 +9,7 @@ import ddt
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from six import text_type
|
||||
|
||||
from openedx.core.djangoapps.user_api import accounts
|
||||
from openedx.core.djangoapps.user_api.accounts.tests import testutils
|
||||
@@ -140,7 +141,7 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase):
|
||||
def test_confirm_email_doesnt_equal_email(self, confirm_email):
|
||||
self.assertValidationDecision(
|
||||
{'email': 'user@email.com', 'confirm_email': confirm_email},
|
||||
{'email': '', 'confirm_email': accounts.REQUIRED_FIELD_CONFIRM_EMAIL_MSG}
|
||||
{'email': '', 'confirm_email': text_type(accounts.REQUIRED_FIELD_CONFIRM_EMAIL_MSG)}
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
@@ -150,7 +151,7 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase):
|
||||
def test_username_bad_length_validation_decision(self, username):
|
||||
self.assertValidationDecision(
|
||||
{'username': username},
|
||||
{'username': accounts.USERNAME_BAD_LENGTH_MSG}
|
||||
{'username': text_type(accounts.USERNAME_BAD_LENGTH_MSG)}
|
||||
)
|
||||
|
||||
@unittest.skipUnless(settings.FEATURES.get("ENABLE_UNICODE_USERNAME"), "Unicode usernames disabled.")
|
||||
@@ -158,7 +159,7 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase):
|
||||
def test_username_invalid_unicode_validation_decision(self, username):
|
||||
self.assertValidationDecision(
|
||||
{'username': username},
|
||||
{'username': accounts.USERNAME_INVALID_CHARS_UNICODE}
|
||||
{'username': text_type(accounts.USERNAME_INVALID_CHARS_UNICODE)}
|
||||
)
|
||||
|
||||
@unittest.skipIf(settings.FEATURES.get("ENABLE_UNICODE_USERNAME"), "Unicode usernames enabled.")
|
||||
@@ -166,31 +167,31 @@ class RegistrationValidationViewTests(test_utils.ApiTestCase):
|
||||
def test_username_invalid_ascii_validation_decision(self, username):
|
||||
self.assertValidationDecision(
|
||||
{'username': username},
|
||||
{"username": accounts.USERNAME_INVALID_CHARS_ASCII}
|
||||
{"username": text_type(accounts.USERNAME_INVALID_CHARS_ASCII)}
|
||||
)
|
||||
|
||||
def test_password_empty_validation_decision(self):
|
||||
self.assertValidationDecision(
|
||||
{'password': ''},
|
||||
{"password": accounts.PASSWORD_EMPTY_MSG}
|
||||
{"password": text_type(accounts.PASSWORD_EMPTY_MSG)}
|
||||
)
|
||||
|
||||
def test_password_bad_min_length_validation_decision(self):
|
||||
password = 'p' * (accounts.PASSWORD_MIN_LENGTH - 1)
|
||||
self.assertValidationDecision(
|
||||
{'password': password},
|
||||
{"password": accounts.PASSWORD_BAD_MIN_LENGTH_MSG}
|
||||
{"password": text_type(accounts.PASSWORD_BAD_MIN_LENGTH_MSG)}
|
||||
)
|
||||
|
||||
def test_password_bad_max_length_validation_decision(self):
|
||||
password = 'p' * (accounts.PASSWORD_MAX_LENGTH + 1)
|
||||
self.assertValidationDecision(
|
||||
{'password': password},
|
||||
{"password": accounts.PASSWORD_BAD_MAX_LENGTH_MSG}
|
||||
{"password": text_type(accounts.PASSWORD_BAD_MAX_LENGTH_MSG)}
|
||||
)
|
||||
|
||||
def test_password_equals_username_validation_decision(self):
|
||||
self.assertValidationDecision(
|
||||
{"username": "somephrase", "password": "somephrase"},
|
||||
{"username": "", "password": accounts.PASSWORD_CANT_EQUAL_USERNAME_MSG}
|
||||
{"username": "", "password": text_type(accounts.PASSWORD_CANT_EQUAL_USERNAME_MSG)}
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@ from opaque_keys.edx.keys import CourseKey
|
||||
from rest_framework import authentication, generics, status, viewsets
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.views import APIView
|
||||
from six import text_type
|
||||
|
||||
import accounts
|
||||
from django_comment_common.models import Role
|
||||
@@ -150,7 +151,7 @@ class RegistrationView(APIView):
|
||||
user = create_account_with_params(request, data)
|
||||
except AccountValidationError as err:
|
||||
errors = {
|
||||
err.field: [{"user_message": err.message}]
|
||||
err.field: [{"user_message": text_type(err)}]
|
||||
}
|
||||
return JsonResponse(errors, status=409)
|
||||
except ValidationError as err:
|
||||
|
||||
Reference in New Issue
Block a user