From af9d4ae5a384b359acb3fe87ee8e0dac1fbd2f4e Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 May 2016 15:56:01 +0100 Subject: [PATCH] Added tests for format filter --- .../tests/test_image_operations.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/wagtail/wagtailimages/tests/test_image_operations.py b/wagtail/wagtailimages/tests/test_image_operations.py index b7d33dc3a3..ec77272f00 100644 --- a/wagtail/wagtailimages/tests/test_image_operations.py +++ b/wagtail/wagtailimages/tests/test_image_operations.py @@ -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())