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

Added tests for format filter

This commit is contained in:
Karl Hobley 2016-05-03 15:56:01 +01:00 committed by Matt Westcott
parent 6c57b5b280
commit af9d4ae5a3

View File

@ -447,3 +447,43 @@ def register_image_operations():
('operation1', Mock(return_value=TestFilter.operation_instance)),
('operation2', Mock(return_value=TestFilter.operation_instance))
]
class TestFormatFilter(TestCase):
def test_jpeg(self):
fil = Filter(spec='width-400|format-jpeg')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
out = fil.run(image, BytesIO())
self.assertEqual(out.format_name, 'jpeg')
def test_png(self):
fil = Filter(spec='width-400|format-png')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
out = fil.run(image, BytesIO())
self.assertEqual(out.format_name, 'png')
def test_gif(self):
fil = Filter(spec='width-400|format-gif')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
out = fil.run(image, BytesIO())
self.assertEqual(out.format_name, 'gif')
def test_invalid(self):
fil = Filter(spec='width-400|format-foo')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
self.assertRaises(InvalidFilterSpecError, fil.run, image, BytesIO())