Commit 178e497c by Syed Hassan Raza

fix None value for orientation update

parent 902d7324
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment