diff --git a/ivatar/ivataraccount/models.py b/ivatar/ivataraccount/models.py index c69830b..b201f61 100644 --- a/ivatar/ivataraccount/models.py +++ b/ivatar/ivataraccount/models.py @@ -47,6 +47,8 @@ def file_format(image_type): return "png" elif image_type == "GIF": return "gif" + elif image_type == "WEBP": + return "webp" return None @@ -60,6 +62,8 @@ def pil_format(image_type): return "PNG" elif image_type == "gif": return "GIF" + elif image_type == "webp": + return "WEBP" logger.info("Unsupported file format: %s", image_type) return None diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index ce60657..59bb331 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -748,6 +748,47 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200, "unable to fetch avatar?") + def test_upload_webp_image(self): + """ + Test if webp is correctly detected and can be viewed + """ + self.login() + url = reverse("upload_photo") + # rb => Read binary + # Broken is _not_ broken - it's just an 'x' :-) + with open( + os.path.join(settings.STATIC_ROOT, "img", "broken.webp"), "rb" + ) as photo: + response = self.client.post( + url, + { + "photo": photo, + "not_porn": True, + "can_distribute": True, + }, + follow=True, + ) + self.assertEqual( + str(list(response.context[0]["messages"])[0]), + "Successfully uploaded", + "WEBP upload failed?!", + ) + self.assertEqual( + self.user.photo_set.first().format, + "webp", + "Format must be webp, since we uploaded a webp!", + ) + self.test_confirm_email() + self.user.confirmedemail_set.first().photo = self.user.photo_set.first() + urlobj = urlsplit( + libravatar_url( + email=self.user.confirmedemail_set.first().email, + ) + ) + url = "%s?%s" % (urlobj.path, urlobj.query) + response = self.client.get(url, follow=True) + self.assertEqual(response.status_code, 200, "unable to fetch avatar?") + def test_upload_unsupported_tif_image(self): # pylint: disable=invalid-name """ Test if unsupported format is correctly detected diff --git a/ivatar/test_auxiliary.py b/ivatar/test_auxiliary.py index 50e9811..b531196 100644 --- a/ivatar/test_auxiliary.py +++ b/ivatar/test_auxiliary.py @@ -37,6 +37,7 @@ class Tester(TestCase): self.assertEqual(pil_format("jpeg"), "JPEG") self.assertEqual(pil_format("png"), "PNG") self.assertEqual(pil_format("gif"), "GIF") + self.assertEqual(pil_format("webp"), "WEBP") self.assertEqual(pil_format("abc"), None) def test_userprefs_str(self):