fix None value for orientation update
This commit is contained in:
@@ -205,7 +205,8 @@ def _update_exif_orientation(exif, orientation):
|
||||
the exif orientation, return a new exif with the orientation set.
|
||||
"""
|
||||
exif_dict = piexif.load(exif)
|
||||
exif_dict['0th'][piexif.ImageIFD.Orientation] = orientation
|
||||
if orientation:
|
||||
exif_dict['0th'][piexif.ImageIFD.Orientation] = orientation
|
||||
return piexif.dump(exif_dict)
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from ..images import (
|
||||
validate_uploaded_image,
|
||||
_get_exif_orientation,
|
||||
_get_valid_file_types,
|
||||
_update_exif_orientation
|
||||
)
|
||||
from .helpers import make_image_file, make_uploaded_file
|
||||
|
||||
@@ -186,6 +187,20 @@ class TestGenerateProfileImages(TestCase):
|
||||
for _, image in self._create_mocked_profile_images(imfile, requested_images):
|
||||
self.check_exif_orientation(image, None)
|
||||
|
||||
def test_update_exif_orientation_without_orientation(self):
|
||||
"""
|
||||
Test the update_exif_orientation without orientation will not throw exception.
|
||||
"""
|
||||
requested_images = {10: "ten.jpg"}
|
||||
with make_image_file(extension='.jpg') as imfile:
|
||||
for _, image in self._create_mocked_profile_images(imfile, requested_images):
|
||||
self.check_exif_orientation(image, None)
|
||||
exif = image.info.get('exif', piexif.dump({}))
|
||||
self.assertEqual(
|
||||
_update_exif_orientation(exif, None),
|
||||
image.info.get('exif', piexif.dump({}))
|
||||
)
|
||||
|
||||
def _create_mocked_profile_images(self, image_file, requested_images):
|
||||
"""
|
||||
Create image files with mocked-out storage.
|
||||
|
||||
Reference in New Issue
Block a user