Merge pull request #19620 from cclauss/new-style-exceptions

Old style exceptions --> new style for Python 3
This commit is contained in:
Jeremy Bowman
2019-02-19 16:31:35 -05:00
committed by GitHub
24 changed files with 60 additions and 58 deletions

View File

@@ -7,6 +7,8 @@ import copy
from unittest import skip
from mock import Mock, patch
from six import text_type
from django.conf import settings
from django.contrib.auth import SESSION_KEY
from django.contrib.auth.models import AnonymousUser, User
@@ -97,7 +99,7 @@ class SSLClientTest(ModuleStoreTestCase):
self.assertIn('<form role="form" id="register-form" method="post"', response.content)
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
with self.assertRaises(User.DoesNotExist):
@@ -116,7 +118,7 @@ class SSLClientTest(ModuleStoreTestCase):
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
with self.assertRaises(User.DoesNotExist):
@@ -135,11 +137,11 @@ class SSLClientTest(ModuleStoreTestCase):
# Assert our user exists in both eamap and Users, and that we are logged in
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to internal users, exception was {0}'.format(str(ex)))
@skip_unless_cms
@@ -161,11 +163,11 @@ class SSLClientTest(ModuleStoreTestCase):
# Assert our user exists in both eamap and Users, and that we are logged in
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to internal users, exception was {0}'.format(str(ex)))
@skip_unless_lms
@@ -322,11 +324,11 @@ class SSLClientTest(ModuleStoreTestCase):
# Assert our user exists in both eamap and Users
try:
ExternalAuthMap.objects.get(external_id=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to external auth map, exception was {0}'.format(str(ex)))
try:
User.objects.get(email=self.USER_EMAIL)
except ExternalAuthMap.DoesNotExist, ex:
except ExternalAuthMap.DoesNotExist as ex:
self.fail(u'User did not get properly added to internal users, exception was {0}'.format(str(ex)))
self.assertEqual(1, len(ExternalAuthMap.objects.all()))
@@ -382,7 +384,7 @@ class SSLClientTest(ModuleStoreTestCase):
CourseEnrollment.enroll(user, course.id)
CourseStaffRole(course.id).add_users(user)
course_private_url = reverse('course_handler', args=(unicode(course.id),))
course_private_url = reverse('course_handler', args=(text_type(course.id),))
self.assertNotIn(SESSION_KEY, self.client.session)
response = self.client.get(

View File

@@ -28,8 +28,8 @@ from ..views import LOG_MESSAGE_CREATE, LOG_MESSAGE_DELETE
from .helpers import make_image_file
TEST_PASSWORD = "test"
TEST_UPLOAD_DT = datetime.datetime(2002, 1, 9, 15, 43, 01, tzinfo=UTC)
TEST_UPLOAD_DT2 = datetime.datetime(2003, 1, 9, 15, 43, 01, tzinfo=UTC)
TEST_UPLOAD_DT = datetime.datetime(2002, 1, 9, 15, 43, 1, tzinfo=UTC)
TEST_UPLOAD_DT2 = datetime.datetime(2003, 1, 9, 15, 43, 1, tzinfo=UTC)
class ProfileImageEndpointMixin(UserSettingsEventTestMixin):

View File

@@ -13,7 +13,7 @@ from student.tests.factories import UserFactory
from ..image_helpers import get_profile_image_urls_for_user
TEST_SIZES = {'full': 50, 'small': 10}
TEST_PROFILE_IMAGE_UPLOAD_DT = datetime.datetime(2002, 1, 9, 15, 43, 01, tzinfo=UTC)
TEST_PROFILE_IMAGE_UPLOAD_DT = datetime.datetime(2002, 1, 9, 15, 43, 1, tzinfo=UTC)
@patch.dict('django.conf.settings.PROFILE_IMAGE_SIZES_MAP', TEST_SIZES, clear=True)