From 0ab0f6bda846fa2c71262fa390d11d22b8ee551a Mon Sep 17 00:00:00 2001 From: Michael Youngstrom Date: Wed, 27 Mar 2019 15:55:24 -0400 Subject: [PATCH 1/2] run python-modernize openedx/core/djangoapps/profile_images --- openedx/core/djangoapps/profile_images/exceptions.py | 2 ++ openedx/core/djangoapps/profile_images/images.py | 5 ++++- openedx/core/djangoapps/profile_images/tests/helpers.py | 8 +++++--- .../core/djangoapps/profile_images/tests/test_images.py | 3 ++- .../core/djangoapps/profile_images/tests/test_views.py | 9 +++++---- openedx/core/djangoapps/profile_images/urls.py | 2 ++ openedx/core/djangoapps/profile_images/views.py | 8 +++++--- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/openedx/core/djangoapps/profile_images/exceptions.py b/openedx/core/djangoapps/profile_images/exceptions.py index 2977a75900..53013b18c9 100644 --- a/openedx/core/djangoapps/profile_images/exceptions.py +++ b/openedx/core/djangoapps/profile_images/exceptions.py @@ -1,6 +1,8 @@ """ Exceptions related to the handling of profile images. """ +from __future__ import absolute_import + from six import text_type diff --git a/openedx/core/djangoapps/profile_images/images.py b/openedx/core/djangoapps/profile_images/images.py index 15d7c5c44b..d067dcbf8f 100644 --- a/openedx/core/djangoapps/profile_images/images.py +++ b/openedx/core/djangoapps/profile_images/images.py @@ -1,11 +1,14 @@ """ Image file manipulation functions related to profile images. """ +from __future__ import absolute_import + from collections import namedtuple from contextlib import closing from cStringIO import StringIO import piexif +import six from django.conf import settings from django.core.files.base import ContentFile from django.utils.translation import ugettext as _ @@ -106,7 +109,7 @@ def validate_uploaded_image(uploaded_file): raise ImageValidationError(file_upload_too_small) # check the file extension looks acceptable - filename = unicode(uploaded_file.name).lower() + filename = six.text_type(uploaded_file.name).lower() filetype = [ft for ft in IMAGE_TYPES if any(filename.endswith(ext) for ext in IMAGE_TYPES[ft].extensions)] if not filetype: file_upload_bad_type = _( diff --git a/openedx/core/djangoapps/profile_images/tests/helpers.py b/openedx/core/djangoapps/profile_images/tests/helpers.py index a3c826bc5e..08693b47d9 100644 --- a/openedx/core/djangoapps/profile_images/tests/helpers.py +++ b/openedx/core/djangoapps/profile_images/tests/helpers.py @@ -1,6 +1,7 @@ """ Helper methods for use in profile image tests. """ +from __future__ import absolute_import from contextlib import contextmanager import os from tempfile import NamedTemporaryFile @@ -8,6 +9,7 @@ from tempfile import NamedTemporaryFile from django.core.files.uploadedfile import UploadedFile import piexif from PIL import Image +from six.moves import range @contextmanager @@ -29,7 +31,7 @@ def make_image_file(dimensions=(320, 240), prefix='tmp', extension='.jpeg', forc image = Image.new('RGB', dimensions, "green") image_file = NamedTemporaryFile(prefix=prefix, suffix=extension) try: - if orientation and orientation in xrange(1, 9): + if orientation and orientation in range(1, 9): exif_bytes = piexif.dump({'0th': {piexif.ImageIFD.Orientation: orientation}}) image.save(image_file, exif=exif_bytes) else: @@ -40,9 +42,9 @@ def make_image_file(dimensions=(320, 240), prefix='tmp', extension='.jpeg', forc # write in hunks of 256 bytes hunk, byte_ = bytearray([0] * 256), bytearray([0]) num_hunks, remainder = divmod(bytes_to_pad, 256) - for _ in xrange(num_hunks): + for _ in range(num_hunks): image_file.write(hunk) - for _ in xrange(remainder): + for _ in range(remainder): image_file.write(byte_) image_file.flush() image_file.seek(0) diff --git a/openedx/core/djangoapps/profile_images/tests/test_images.py b/openedx/core/djangoapps/profile_images/tests/test_images.py index a58ffcf9d4..56c40476f0 100644 --- a/openedx/core/djangoapps/profile_images/tests/test_images.py +++ b/openedx/core/djangoapps/profile_images/tests/test_images.py @@ -1,6 +1,7 @@ """ Test cases for image processing functions in the profile image package. """ +from __future__ import absolute_import from contextlib import closing from itertools import product import os @@ -243,5 +244,5 @@ class TestRemoveProfileImages(TestCase): ): remove_profile_images(requested_sizes) deleted_names = [v[0][0] for v in mock_storage.delete.call_args_list] - self.assertEqual(requested_sizes.values(), deleted_names) + self.assertEqual(list(requested_sizes.values()), deleted_names) mock_storage.save.reset_mock() diff --git a/openedx/core/djangoapps/profile_images/tests/test_views.py b/openedx/core/djangoapps/profile_images/tests/test_views.py index a79c08bd57..3a6d18741c 100644 --- a/openedx/core/djangoapps/profile_images/tests/test_views.py +++ b/openedx/core/djangoapps/profile_images/tests/test_views.py @@ -1,6 +1,7 @@ """ Test cases for the HTTP endpoints of the profile image api. """ +from __future__ import absolute_import from contextlib import closing import datetime from pytz import UTC @@ -178,7 +179,7 @@ class ProfileImageViewPostTestCase(ProfileImageEndpointMixin, APITestCase): self.check_has_profile_image() mock_log.info.assert_called_once_with( LOG_MESSAGE_CREATE, - {'image_names': get_profile_image_names(self.user.username).values(), 'user_id': self.user.id} + {'image_names': list(get_profile_image_names(self.user.username).values()), 'user_id': self.user.id} ) self.check_upload_event_emitted() @@ -217,7 +218,7 @@ class ProfileImageViewPostTestCase(ProfileImageEndpointMixin, APITestCase): self.check_has_profile_image() mock_log.info.assert_called_once_with( LOG_MESSAGE_CREATE, - {'image_names': get_profile_image_names(self.user.username).values(), 'user_id': self.user.id} + {'image_names': list(get_profile_image_names(self.user.username).values()), 'user_id': self.user.id} ) self.check_upload_event_emitted() @@ -400,7 +401,7 @@ class ProfileImageViewDeleteTestCase(ProfileImageEndpointMixin, APITestCase): self.check_has_profile_image(False) mock_log.info.assert_called_once_with( LOG_MESSAGE_DELETE, - {'image_names': get_profile_image_names(self.user.username).values(), 'user_id': self.user.id} + {'image_names': list(get_profile_image_names(self.user.username).values()), 'user_id': self.user.id} ) self.check_remove_event_emitted() @@ -435,7 +436,7 @@ class ProfileImageViewDeleteTestCase(ProfileImageEndpointMixin, APITestCase): self.check_has_profile_image(False) mock_log.info.assert_called_once_with( LOG_MESSAGE_DELETE, - {'image_names': get_profile_image_names(self.user.username).values(), 'user_id': self.user.id} + {'image_names': list(get_profile_image_names(self.user.username).values()), 'user_id': self.user.id} ) self.check_remove_event_emitted() diff --git a/openedx/core/djangoapps/profile_images/urls.py b/openedx/core/djangoapps/profile_images/urls.py index 06e6d0529f..d2bc6e0078 100644 --- a/openedx/core/djangoapps/profile_images/urls.py +++ b/openedx/core/djangoapps/profile_images/urls.py @@ -8,6 +8,8 @@ NOTE: These views are deprecated. These routes are superseded by """ # pylint: enable=unicode-format-string +from __future__ import absolute_import + from django.conf import settings from django.conf.urls import url diff --git a/openedx/core/djangoapps/profile_images/views.py b/openedx/core/djangoapps/profile_images/views.py index 2d5512e168..8cee2b2588 100644 --- a/openedx/core/djangoapps/profile_images/views.py +++ b/openedx/core/djangoapps/profile_images/views.py @@ -1,15 +1,17 @@ """ This module implements the upload and remove endpoints of the profile image api. """ +from __future__ import absolute_import + import datetime import itertools import logging from contextlib import closing -from pytz import UTC from django.utils.translation import ugettext as _ from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser +from pytz import UTC from rest_framework import permissions, status from rest_framework.parsers import FormParser, MultiPartParser from rest_framework.response import Response @@ -162,7 +164,7 @@ class ProfileImageView(DeveloperErrorViewMixin, APIView): log.info( LOG_MESSAGE_CREATE, - {'image_names': profile_image_names.values(), 'user_id': request.user.id} + {'image_names': list(profile_image_names.values()), 'user_id': request.user.id} ) # send client response. @@ -183,7 +185,7 @@ class ProfileImageView(DeveloperErrorViewMixin, APIView): log.info( LOG_MESSAGE_DELETE, - {'image_names': profile_image_names.values(), 'user_id': request.user.id} + {'image_names': list(profile_image_names.values()), 'user_id': request.user.id} ) except UserNotFound: return Response(status=status.HTTP_404_NOT_FOUND) From 43e6cb871ba3a79264f465a54ffc2acf16112a24 Mon Sep 17 00:00:00 2001 From: Matt Hughes Date: Thu, 28 Mar 2019 10:32:51 -0400 Subject: [PATCH 2/2] Fix bug with missing exam timer numbers --- requirements/constraints.txt | 2 +- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/testing.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 949787eb4e..4148d98a33 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -46,4 +46,4 @@ pytest-randomly<2.0.0 tornado<6.0 # Preventing https://github.com/edx/edx-proctoring/pull/557 being installed before https://github.com/edx/edx-platform/pull/19959 -edx-proctoring==1.5.21 +edx-proctoring==1.5.22 diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index b92c30f3b8..ab38ab4f0b 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -120,7 +120,7 @@ edx-oauth2-provider==1.2.2 edx-opaque-keys[django]==0.4.4 edx-organizations==1.0.1 edx-proctoring-proctortrack==1.0.4 -edx-proctoring==1.5.21 +edx-proctoring==1.5.22 edx-rbac==0.1.5 # via edx-enterprise edx-rest-api-client==1.9.2 edx-search==1.2.2 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index f6dc9c80b9..daffd115ec 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -143,7 +143,7 @@ edx-oauth2-provider==1.2.2 edx-opaque-keys[django]==0.4.4 edx-organizations==1.0.1 edx-proctoring-proctortrack==1.0.4 -edx-proctoring==1.5.21 +edx-proctoring==1.5.22 edx-rbac==0.1.5 edx-rest-api-client==1.9.2 edx-search==1.2.2 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 8b22de6e62..476fc2bfe2 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -139,7 +139,7 @@ edx-oauth2-provider==1.2.2 edx-opaque-keys[django]==0.4.4 edx-organizations==1.0.1 edx-proctoring-proctortrack==1.0.4 -edx-proctoring==1.5.21 +edx-proctoring==1.5.22 edx-rbac==0.1.5 edx-rest-api-client==1.9.2 edx-search==1.2.2