0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Add more SVG tests

This commit is contained in:
Joshua Munn 2023-01-03 17:31:23 +00:00 committed by Matt Westcott
parent 196ed4162d
commit ef12245351
4 changed files with 63 additions and 1 deletions

View File

@ -31,7 +31,7 @@ from wagtail.test.testapp.models import (
)
from wagtail.test.utils import WagtailTestUtils
from .utils import Image, get_test_image_file
from .utils import Image, get_test_image_file, get_test_image_file_svg
# Get the chars that Django considers safe to leave unescaped in a URL
urlquote_safechars = RFC3986_SUBDELIMS + str("/~:@")
@ -524,6 +524,25 @@ class TestImageAddView(WagtailTestUtils, TestCase):
root_collection = Collection.get_first_root_node()
self.assertEqual(image.collection, root_collection)
def test_add_svg(self):
response = self.post(
{
"title": "Test image",
"file": SimpleUploadedFile(
"test.svg",
get_test_image_file_svg().file.getvalue(),
content_type="text/html",
),
}
)
# Should redirect back to index
self.assertRedirects(response, reverse("wagtailimages:index"))
# Check that the image was created
images = Image.objects.filter(title="Test image")
self.assertEqual(images.count(), 1)
@override_settings(
DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage"
)

View File

@ -913,3 +913,38 @@ class TestWebpFormatConversion(TestCase):
out = fil.run(image, BytesIO())
self.assertEqual(out.format_name, "webp")
class TestCheckSize(TestCase):
def test_check_size_when_floats_allowed(self):
sizes = [
(1.5, 1.5),
(1.5, 1),
(1, 1.5),
(1, 1),
]
for size in sizes:
with self.subTest(size=size):
self.assertIsNone(
image_operations.ImageTransform._check_size(
size, allow_floating_point=True
)
)
def test_check_size_when_floats_forbidden(self):
fail_sizes = [
(1.5, 1.5),
(1.5, 1),
(1, 1.5),
]
for size in fail_sizes:
with self.subTest(size=size):
with self.assertRaises(TypeError):
image_operations.ImageTransform._check_size(
size, allow_floating_point=False
)
self.assertIsNone(
image_operations.ImageTransform._check_size(
(1, 1), allow_floating_point=False
)
)

View File

@ -88,6 +88,12 @@ class ImageNodeTestCase(TestCase):
["fill-400x400", "format-webp", "webpquality-50"],
"fill-400x400|format-webp|webpquality-50",
),
(self.svg_image, ["max-400x400"], "max-400x400"),
(self.svg_image, ["min-400x400"], "min-400x400"),
(self.svg_image, ["width-300"], "width-300"),
(self.svg_image, ["height-300"], "height-300"),
(self.svg_image, ["scale-50"], "scale-50"),
(self.svg_image, ["fill-400x400"], "fill-400x400"),
]
for image, filter_specs, expected in params:
with self.subTest(img=image, filter_specs=filter_specs, expected=expected):

View File

@ -257,3 +257,5 @@ MESSAGE_TAGS = {
message_constants.WARNING: "my-custom-tag",
message_constants.ERROR: "my-custom-tag",
}
WAGTAILIMAGES_ALLOW_SVG = True