additional magic test

This commit is contained in:
Johannes Wilm 2022-08-15 12:03:54 +02:00
parent a89a3fad17
commit d0ed3e3132
2 changed files with 13 additions and 1 deletions

View file

@ -140,7 +140,7 @@ class Avatar(models.Model):
try:
orientation = image._getexif()[0x0112]
ops = EXIF_ORIENTATION_STEPS[orientation]
except TypeError:
except (AttributeError, TypeError):
ops = []
for method in ops:
image = image.transpose(getattr(Image, method))

View file

@ -129,6 +129,18 @@ class AvatarTests(TestCase):
self.assertEqual(len(response.redirect_chain), 0) # Redirect only if it worked
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
# We allow the .tiff file extension and the mime type
@override_settings(AVATAR_ALLOWED_FILE_EXTS=(".png", ".gif", ".jpg", ".tiff"))
@override_settings(
AVATAR_ALLOWED_MIMETYPES=("image/png", "image/gif", "image/jpeg", "image/tiff")
)
def test_supported_image_format_upload(self):
"""Check with python-magic that we detect corrupted / unapprovd image files correctly"""
response = upload_helper(self, "test.tiff")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.redirect_chain), 1) # Redirect only if it worked
self.assertEqual(response.context["upload_avatar_form"].errors, {})
@override_settings(AVATAR_ALLOWED_FILE_EXTS=(".jpg", ".png"))
def test_image_without_wrong_extension(self):
response = upload_helper(self, "imagefilewithoutext")