mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-12 03:06:24 +00:00
Webp support
This commit is contained in:
@@ -47,6 +47,8 @@ def file_format(image_type):
|
|||||||
return "png"
|
return "png"
|
||||||
elif image_type == "GIF":
|
elif image_type == "GIF":
|
||||||
return "gif"
|
return "gif"
|
||||||
|
elif image_type == "WEBP":
|
||||||
|
return "webp"
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +62,8 @@ def pil_format(image_type):
|
|||||||
return "PNG"
|
return "PNG"
|
||||||
elif image_type == "gif":
|
elif image_type == "gif":
|
||||||
return "GIF"
|
return "GIF"
|
||||||
|
elif image_type == "webp":
|
||||||
|
return "WEBP"
|
||||||
|
|
||||||
logger.info("Unsupported file format: %s", image_type)
|
logger.info("Unsupported file format: %s", image_type)
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -748,6 +748,47 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
|
|||||||
response = self.client.get(url, follow=True)
|
response = self.client.get(url, follow=True)
|
||||||
self.assertEqual(response.status_code, 200, "unable to fetch avatar?")
|
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
|
def test_upload_unsupported_tif_image(self): # pylint: disable=invalid-name
|
||||||
"""
|
"""
|
||||||
Test if unsupported format is correctly detected
|
Test if unsupported format is correctly detected
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class Tester(TestCase):
|
|||||||
self.assertEqual(pil_format("jpeg"), "JPEG")
|
self.assertEqual(pil_format("jpeg"), "JPEG")
|
||||||
self.assertEqual(pil_format("png"), "PNG")
|
self.assertEqual(pil_format("png"), "PNG")
|
||||||
self.assertEqual(pil_format("gif"), "GIF")
|
self.assertEqual(pil_format("gif"), "GIF")
|
||||||
|
self.assertEqual(pil_format("webp"), "WEBP")
|
||||||
self.assertEqual(pil_format("abc"), None)
|
self.assertEqual(pil_format("abc"), None)
|
||||||
|
|
||||||
def test_userprefs_str(self):
|
def test_userprefs_str(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user