Merge branch 'master' into coryleeio/remove_aws_py
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Exceptions related to the handling of profile images.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from six import text_type
|
||||
|
||||
|
||||
|
||||
@@ -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 = _(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user